From 769442772 at qq.com Sun Apr 24 03:45:17 2022 From: 769442772 at qq.com (=?UTF-8?B?5LqU5b2p55+z?=) Date: Sun Apr 24 10:35:30 2022 Subject: [odb-users] how compile odb on windows? Message-ID: I tried use /"odb-2.4.0-i686-windows"/, /c++11-sqlite-vc12/ project is compile and run normally in odb-examples-2.4.0,but compile /"qt5-sqlite-vc12" /have warning:D:/Qt/5.15.2/msvc2019/include/QtCore/qbasicatomic.h(61,4): error GBD81D969: #error "Qt requires C++11 support"?edit odb\etc\odb\default.options add options /-I D:/Qt/5.15.2/msvc2019/include/ and /--std c++11/,It still doesn't work? How does it work in windows,please. From boris at codesynthesis.com Sun Apr 24 10:44:55 2022 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Apr 24 10:41:05 2022 Subject: [odb-users] how compile odb on windows? In-Reply-To: References: Message-ID: ??? <769442772@qq.com> writes: > I tried use /"odb-2.4.0-i686-windows"/, /c++11-sqlite-vc12/ project is > compile and run normally in odb-examples-2.4.0,but compile > /"qt5-sqlite-vc12" /have > warning:D:/Qt/5.15.2/msvc2019/include/QtCore/qbasicatomic.h(61,4): error > GBD81D969: #error "Qt requires C++11 support" edit > odb\etc\odb\default.options add options /-I D:/Qt/5.15.2/msvc2019/include/ > and /--std c++11/,It still doesn't work I am not sure why Qt still complains about C++11 after you've added --std c++11. Perhaps GCC bundled with ODB 2.4.0 is too old. You could try the latest pre-release of ODB (which uses a more recent version of GCC) by following these instructions: https://codesynthesis.com/products/xsd/doc/install-build2.xhtml From stef.dalbosco at hotmail.com Wed Apr 27 06:23:28 2022 From: stef.dalbosco at hotmail.com (stef dalbosco) Date: Wed Apr 27 06:19:45 2022 Subject: [odb-users] Custom migration functions fails when migrating multiple versions Message-ID: Hi, I have a db object that has a member that I want to fill in at run time. So I registered a migration function that fills in that member when migrating to that version. In this migration function, I loaded in the object because the default value is depended on the other members. This worked as expected until a new version was added that added a new member. If I now migrate both versions at the same time, my custom migration function crashes when I query. I think this is because it calls code that is already for the newest version but the schema is still in between. Is there a way to fix this? I could register my migration function with the latest version so during migration it will be called last. But I'm not confident this is a permanently solution. See example below for clearer description. I have a object Person with a name and a guid that is depended on the name: #pragma db object struct Person //created in version 1 { #pragma db id auto unsigned id_; std::string name_; #pragma db default("") std::string guid_; //added in version 2 std::string email_; //added in version 3 } After generating I get two schema migration functions which both will add a column: static const schema_catalog_migrate_entry migrate_schema_entry_2_ (id_sqlite, "lib", 2ULL, &migrate_schema_2); static const schema_catalog_migrate_entry migrate_schema_entry_3_ (id_sqlite, "lib", 3ULL, &migrate_schema_3); And this is my custom migration: static void migrate_GUIDS(odb::database& db) { auto persons = db.query(); for (auto it = persons.begin(); it != persons.end(); ++it) { auto pPerson = it.load(); if (!pPerson->guid().value.isEmpty()) continue; pComposition->set_guid(/*generate guid depended on name*/); db.update(pComposition); } } odb::schema_catalog::data_migration_function(db, 2ULL, &migrate_GUIDS, "lib"); For this example, if I migrate a db that is on version 1 to version 3, the migration will call the functions in this order 1. migrate_schema_2 that adds the guid column 2. migrate_GUIDS that fills in the guid 3. migrate_schema_3 that adds the email column But migrate_GUIDS will crash on the line db.query() because the query statement is from the form: SELECT "person"."id", "person"."name", "person"."guid", "person"."email" FROM "person" At that time person.email is not added yet. Thanks in advance for your help, Stef From boris at codesynthesis.com Wed Apr 27 06:49:40 2022 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Apr 27 06:45:49 2022 Subject: [odb-users] Custom migration functions fails when migrating multiple versions In-Reply-To: References: Message-ID: stef dalbosco writes: > I have a db object that has a member that I want to fill in at run time. So > I registered a migration function that fills in that member when migrating > to that version. > > In this migration function, I loaded in the object because the default value > is depended on the other members. This worked as expected until a new > version was added that added a new member. > > If I now migrate both versions at the same time, my custom migration > function crashes when I query. I think this is because it calls code that is > already for the newest version but the schema is still in between. I am pretty sure what you are looking for are "Soft Object Model Changes": https://codesynthesis.com/products/odb/doc/manual.xhtml#13.4