From linyilong3 at qq.com Sun Oct 6 05:28:26 2019 From: linyilong3 at qq.com (=?gb18030?B?wdbS5sG8?=) Date: Mon Oct 7 06:21:41 2019 Subject: [odb-users] Why this error message occur? Message-ID: I execute the command odb.exe -d sqlite --generate-query --generate-schema person.hxx but occur this message: odb.exe: error: ??????????? in english means: The system could not find the specified path odb.exe and person.hxx has in this directory, why report this error? thanks?? System: Window 10 X64 ODB VERSION: odb-2.4.0-i686-windows From boris at codesynthesis.com Mon Oct 7 07:00:04 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 7 07:05:28 2019 Subject: [odb-users] Why this error message occur? In-Reply-To: References: Message-ID: ??? writes: > in english means: The system could not find the specified path > > odb.exe and person.hxx has in this directory, why report this error? > > ODB VERSION: odb-2.4.0-i686-windows You cannot copy odb.exe around since it depends on other components inside odb-2.4.0-i686-windows which it locates relative to its own location. From yohuang at nvidia.com Mon Oct 14 01:58:35 2019 From: yohuang at nvidia.com (Justin Huang) Date: Mon Oct 14 07:37:23 2019 Subject: [odb-users] How to persist cyclic pointers among A->B->C->A? Message-ID: Hi, If I have three classes A, B and C, and A has pointer to object of class B, B has pointer to object of C, and C has pointer to object of A, which is a cyclic pointer relationship. How should I persist objects a1/a2/b1/c1? E.g., the persistent sequence, and how to avoid persist same objects twice? // class definitions class A { public: std::string name_; B *b_; }; class B { public: std::string name_; C *c; }; class C { public: std::string name_; A *a; }; // objects created A *a1 = new A("A1"); A *a2 = new A("A2"); B *b1 = new B("B1"); C *c1 = new C("C1"); a1->set_b(b1); a2->set_b(b1); b1->set_c(c1); c1->set_a(a1); thanks, Justin ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- From marko.mocnik at lisec.com Mon Oct 14 09:05:03 2019 From: marko.mocnik at lisec.com (Mocnik Marko) Date: Mon Oct 14 09:11:01 2019 Subject: [odb-users] One-to-many bidirectional relationship without intermediary table Message-ID: Hi, I'm trying to map two tables of the form: CREATE TABLE testi ( asdf integer NOT NULL, description varchar(500), CONSTRAINT testi_pkey PRIMARY KEY (asdf) ) CREATE TABLE testi2 ( asdf integer NOT NULL, qwer integer NOT NULL, moredata varchar(100), CONSTRAINT pk_testi2 PRIMARY KEY (asdf, qwer), CONSTRAINT fk_t2_t FOREIGN KEY (asdf) REFERENCES testi (asdf) ) I know that's not pretty, but we have some legacy tables that have this kind of relationship. Is there any way to map this and if so, how? The only way I could manage to get a mapping to compile produced a stack overflow when running a query... Also, is it possible to use two separate headers for testi and testi2? I could not get this to compile because in one of the files I would need to use a forward declaration instead of a direct include and then the compiler would not find the appropriate template specializations. Thanks, Marko From boris at codesynthesis.com Mon Oct 14 09:34:21 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 14 09:40:07 2019 Subject: [odb-users] How to persist cyclic pointers among A->B->C->A? In-Reply-To: References: Message-ID: Justin Huang writes: > If I have three classes A, B and C, and A has pointer to object of class B, > B has pointer to object of C, and C has pointer to object of A, which is a > cyclic pointer relationship. > > How should I persist objects a1/a2/b1/c1? E.g., the persistent sequence, > and how to avoid persist same objects twice? You can persist them in any order (within the same transaction) provided their ids have been assigned (which could be problematic if you use auto- assigned ids). You will also have to somehow make sure you are not persising the same object twice. One way would be to use the session (object cache) and check if each object is already there before persisting it: https://codesynthesis.com/products/odb/doc/manual.xhtml#11 From boris at codesynthesis.com Mon Oct 14 10:11:45 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 14 10:17:31 2019 Subject: [odb-users] One-to-many bidirectional relationship without intermediary table In-Reply-To: References: Message-ID: Mocnik Marko writes: > I'm trying to map two tables of the form: > > CREATE TABLE testi > ( > asdf integer NOT NULL, > description varchar(500), > CONSTRAINT testi_pkey PRIMARY KEY (asdf) > ) > > CREATE TABLE testi2 > ( > asdf integer NOT NULL, > qwer integer NOT NULL, > moredata varchar(100), > CONSTRAINT pk_testi2 PRIMARY KEY (asdf, qwer), > CONSTRAINT fk_t2_t FOREIGN KEY (asdf) REFERENCES testi (asdf) > ) > > I know that's not pretty, but we have some legacy tables that have > this kind of relationship. Is there any way to map this and if so, how? This is actually a pretty standard one-to-many mapping except for the foreign key (testi2.asdf) also being part of the primary key, which is something we don't yet support in ODB out of the box. I was able to get the identical mapping using these classes: #pragma db object struct testi { #pragma db id int asdf; }; #pragma db object struct testi2 { #pragma db value struct id_type { #pragma db points_to(testi) int asdf; int qwer; }; #pragma db id column("") id_type id; }; The generated database schema (PostgreSQL version): CREATE TABLE "testi" ( "asdf" INTEGER NOT NULL PRIMARY KEY); CREATE TABLE "testi2" ( "asdf" INTEGER NOT NULL, "qwer" INTEGER NOT NULL, PRIMARY KEY ("asdf", "qwer"), CONSTRAINT "asdf_fk" FOREIGN KEY ("asdf") REFERENCES "testi" ("asdf") INITIALLY DEFERRED); With virtual data members and a bit of effort you should be able to change testi2::id_type::asdf to a pointer, something along these lines (a sketch): #pragma db object struct testi2 { #pragma db transient testi* asdf; #pragma db transient int qwer; #pragma db value struct id_type { #pragma db points_to(testi) int asdf; int qwer; }; #pragma db member(id) virtual(id_type) id column("") \ get (...) \ set (...) }; More information on virtual data members: https://codesynthesis.com/products/odb/doc/manual.xhtml#14.4.13 > The only way I could manage to get a mapping to compile produced a > stack overflow when running a query... It's hard to say what's wrong without seeing the code. > Also, is it possible to use two separate headers for testi and testi2? > I could not get this to compile because in one of the files I would > need to use a forward declaration instead of a direct include and > then the compiler would not find the appropriate template specializations. Maybe this will help: https://codesynthesis.com/products/odb/doc/manual.xhtml#6.3 From yohuang at nvidia.com Mon Oct 14 09:46:33 2019 From: yohuang at nvidia.com (Justin Huang) Date: Mon Oct 14 10:19:02 2019 Subject: [odb-users] How to persist cyclic pointers among A->B->C->A? In-Reply-To: References: Message-ID: Hi Boris, Thanks for quick response! >> You can persist them in any order (within the same transaction) provided their ids have been assigned (which could be problematic if you use auto- assigned ids). I am using '#pragma db id auto' currently and got 'foreign key constraint failed' error at runtime. I think persistence in this case is order dependent, and I will try to use '#pragma db id' instead and assign 'id' manually. For this kind of pointer chain loop, do I need to set any 'inverse' data member pragma? If I have X -> Y, Y -> X bidirectional relationship, what's the impact if I do not use the 'inverse' pragma ( I manually set 'id')? >> One way would be to use the session (object cache) and check if each object is already there before persisting it: Good idea. I'll check examples in the manual on how to use it. Currently I am throwing exception using pre-persistence check for each db->persist(object) and ignore the exception which seems avoided duplicated entry in the table. Thanks, Justin -----Original Message----- From: Boris Kolpackov Sent: Monday, October 14, 2019 9:34 PM To: Justin Huang Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] How to persist cyclic pointers among A->B->C->A? Justin Huang writes: > If I have three classes A, B and C, and A has pointer to object of > class B, B has pointer to object of C, and C has pointer to object of > A, which is a cyclic pointer relationship. > > How should I persist objects a1/a2/b1/c1? E.g., the persistent > sequence, and how to avoid persist same objects twice? You can persist them in any order (within the same transaction) provided their ids have been assigned (which could be problematic if you use auto- assigned ids). You will also have to somehow make sure you are not persising the same object twice. One way would be to use the session (object cache) and check if each object is already there before persisting it: https://codesynthesis.com/products/odb/doc/manual.xhtml#11 ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- From yohuang at nvidia.com Mon Oct 14 10:59:30 2019 From: yohuang at nvidia.com (Justin Huang) Date: Tue Oct 15 04:11:52 2019 Subject: [odb-users] How to persist cyclic pointers among A->B->C->A? In-Reply-To: References: Message-ID: >> One way would be to use the session (object cache) and check if each object is already there before persisting it: Is there concrete example? I guess I will need to use 'session s;' and use db->load() or s.cache_find(db, ) to test if the object has been persisted? -----Original Message----- From: Justin Huang Sent: Monday, October 14, 2019 9:47 PM To: odb-users@codesynthesis.com Subject: RE: [odb-users] How to persist cyclic pointers among A->B->C->A? Hi Boris, Thanks for quick response! >> You can persist them in any order (within the same transaction) provided their ids have been assigned (which could be problematic if you use auto- assigned ids). I am using '#pragma db id auto' currently and got 'foreign key constraint failed' error at runtime. I think persistence in this case is order dependent, and I will try to use '#pragma db id' instead and assign 'id' manually. For this kind of pointer chain loop, do I need to set any 'inverse' data member pragma? If I have X -> Y, Y -> X bidirectional relationship, what's the impact if I do not use the 'inverse' pragma ( I manually set 'id')? >> One way would be to use the session (object cache) and check if each object is already there before persisting it: Good idea. I'll check examples in the manual on how to use it. Currently I am throwing exception using pre-persistence check for each db->persist(object) and ignore the exception which seems avoided duplicated entry in the table. Thanks, Justin -----Original Message----- From: Boris Kolpackov Sent: Monday, October 14, 2019 9:34 PM To: Justin Huang Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] How to persist cyclic pointers among A->B->C->A? Justin Huang writes: > If I have three classes A, B and C, and A has pointer to object of > class B, B has pointer to object of C, and C has pointer to object of > A, which is a cyclic pointer relationship. > > How should I persist objects a1/a2/b1/c1? E.g., the persistent > sequence, and how to avoid persist same objects twice? You can persist them in any order (within the same transaction) provided their ids have been assigned (which could be problematic if you use auto- assigned ids). You will also have to somehow make sure you are not persising the same object twice. One way would be to use the session (object cache) and check if each object is already there before persisting it: https://codesynthesis.com/products/odb/doc/manual.xhtml#11 ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- From per.edin at sequence-point.se Mon Oct 14 16:12:46 2019 From: per.edin at sequence-point.se (Per Edin) Date: Tue Oct 15 04:11:52 2019 Subject: [odb-users] Sharing common object between multiple ODB schemas Message-ID: Hi! I'm having two different sets of ODB schemas in my application, core and extras. // core/user.hxx // #include namespace core { #pragma db my_app::object class user { #pragma db id uuid id; // ... }; } // extras/profile.hxx // #include namespace my_app::extras { #pragma db object class profile { #pragma db id uuid id; // ... }; } // uuid.hxx // namespace my_app { #pragma db value class uuid { // ... }; } I process these and the other files in core/ and extras/ like this: odb ... --at-once --schema-name core core/core.hxx odb ... --at-once --schema-name extras extras/extras.hxx core/core.hxx and extras/extras.hxx includes all headers belonging to the respective schemas. As can be seen the uuid class is shared between the two schemas. Can you recommend a way to handle this? Currently, the database code for class my_app::uuid ends up in both core-odb._xx and profile-odb._xx resulting in duplicate symbols. I guess I could just copy uuid.hxx to both core/ and extras/ but that doesn't feel right. A part from sharing some value types, the two schemas are completely unrelated. Kind regards Per Edin Sequence Point AB From yohuang at nvidia.com Mon Oct 14 23:27:52 2019 From: yohuang at nvidia.com (Justin Huang) Date: Tue Oct 15 04:11:52 2019 Subject: [odb-users] How to use 'session' to check if an object is already persisted? Message-ID: Hi, I read through https://codesynthesis.com/products/odb/doc/manual.xhtml#11.2 but do not know how we can test if an object is persisted already in the session cache. Is there any example code on this? Should I persist the object and then load it back using its 'id' and test if the returned pointer is NULL? Thanks, Justin ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- From marko.mocnik at lisec.com Tue Oct 15 05:56:57 2019 From: marko.mocnik at lisec.com (Mocnik Marko) Date: Tue Oct 15 06:02:57 2019 Subject: AW: [odb-users] One-to-many bidirectional relationship without intermediary table In-Reply-To: References: Message-ID: Okay, the generated SQL does look pretty good with the 'points_to' directive. (Took me some time to realize that this requires odb 2.5) And I got the virtual data member mapping in testi2 to work like you sketched. But how do I get now a bidirectional mapping? Especially a vector of Testi2 s in Testi? Also with a virtual data member? The docs did not help me on how to do that with a vector. > I was able to get the identical mapping using these classes: > > #pragma db object > struct testi > { > #pragma db id > int asdf; > }; > > #pragma db object > struct testi2 > { > #pragma db value > struct id_type > { > #pragma db points_to(testi) > int asdf; > int qwer; > }; > > #pragma db id column("") > id_type id; > }; > > The generated database schema (PostgreSQL version): > > CREATE TABLE "testi" ( > "asdf" INTEGER NOT NULL PRIMARY KEY); > > CREATE TABLE "testi2" ( > "asdf" INTEGER NOT NULL, > "qwer" INTEGER NOT NULL, > PRIMARY KEY ("asdf", > "qwer"), > CONSTRAINT "asdf_fk" > FOREIGN KEY ("asdf") > REFERENCES "testi" ("asdf") > INITIALLY DEFERRED); > > With virtual data members and a bit of effort you should be able to change testi2::id_type::asdf to a pointer, something along these lines (a sketch): > > #pragma db object > struct testi2 > { > #pragma db transient > testi* asdf; > > #pragma db transient > int qwer; > > #pragma db value > struct id_type > { > #pragma db points_to(testi) > int asdf; > int qwer; > }; > > #pragma db member(id) virtual(id_type) id column("") \ > get (...) \ > set (...) > }; From boris at codesynthesis.com Tue Oct 15 10:08:41 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 15 10:14:33 2019 Subject: [odb-users] One-to-many bidirectional relationship without intermediary table In-Reply-To: References: Message-ID: Mocnik Marko writes: > But how do I get now a bidirectional mapping? Especially a vector of > Testi2 s in Testi? Also with a virtual data member? For the other direction you would want to use the inverse pragma, something along these lines: struct testi2; #pragma db object struct testi { #pragma db id int asdf; #pragma db inverse(id.asdf) std::vector testi2s; }; For more information on the inverse pragma, see: https://codesynthesis.com/products/odb/doc/manual.xhtml#6.2 From boris at codesynthesis.com Tue Oct 15 10:16:01 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 15 10:21:50 2019 Subject: [odb-users] Sharing common object between multiple ODB schemas In-Reply-To: References: Message-ID: Per Edin writes: > odb ... --at-once --schema-name core core/core.hxx > odb ... --at-once --schema-name extras extras/extras.hxx > > core/core.hxx and extras/extras.hxx includes all headers belonging to > the respective schemas. > > As can be seen the uuid class is shared between the two schemas. Can > you recommend a way to handle this? Currently, the database code for > class my_app::uuid ends up in both core-odb._xx and profile-odb._xx > resulting in duplicate symbols. The only way is not to use the --at-once mode for the C++ code generation. This way you would compile uuid.hxx separately with core and extras' *-odb files including uuid-odb.hxx. > I guess I could just copy uuid.hxx to both core/ and extras/ but that > doesn't feel right. That's the only way to make it work in the --at-once mode (you could avoid physical copy by including the header inside a namespace). From boris at codesynthesis.com Tue Oct 15 10:23:51 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 15 10:29:40 2019 Subject: [odb-users] How to use 'session' to check if an object is already persisted? In-Reply-To: References: Message-ID: Justin Huang writes: > I read through https://codesynthesis.com/products/odb/doc/manual.xhtml#11.2 > but do not know how we can test if an object is persisted already in the > session cache. For context, this is a continuation of a thread started here: https://www.codesynthesis.com/pipermail/odb-users/2019-October/004349.html The suggestion there was to use a session as an object cache to suppress duplicate persists within the same transaction. If an object has session support (the db session pragma), then when you persist it (with a call to persist()), it will be automatically entered into the cache. So the idea is to use session::cache_find() before calling persist() to check if that has already happened. From marko.mocnik at lisec.com Tue Oct 15 12:15:10 2019 From: marko.mocnik at lisec.com (Mocnik Marko) Date: Tue Oct 15 12:21:10 2019 Subject: AW: [odb-users] One-to-many bidirectional relationship without intermediary table In-Reply-To: References: Message-ID: What am I doing wrong? I can't get the generated code to compile (sorry about the german compiler messages but I guess the meaning is clear?): TestiAll-odb-pgsql.h(151): error C2027: Verwendung des undefinierten Typs "odb::access::composite_value_traits" TestiAll-odb-pgsql.h(151): note: Siehe Deklaration von "odb::access::composite_value_traits" TestiAll-odb-pgsql.cpp(150): error C2664: "void odb::access::composite_value_traits::bind(odb::pgsql::bind *,odb::access::composite_value_traits::image_type &,odb::pgsql::statement_kind)" : Konvertierung von Argument 2 von "odb::access::object_traits_impl::image_type" in "odb::access::composite_value_traits::image_type &" nicht m"glich TestiAll-odb-pgsql.cpp(162): error C2664: "bool odb::access::composite_value_traits::grow(odb::access::composite_value_traits::image_type &,bool *)" : Konvertierung von Argument 1 von "odb::access::object_traits_impl::image_type" in "odb::access::composite_value_traits::image_type &" nicht m"glich TestiAll-odb-pgsql.cpp(183): error C2664: "bool odb::access::composite_value_traits::get_null(const odb::access::composite_value_traits::image_type &)" : Konvertierung von Argument 1 von "const odb::access::object_traits_impl::image_type" in "const odb::access::composite_value_traits::image_type &" nicht m"glich TestiAll-odb-pgsql.cpp(183): note: Ursache: Konvertierung von "const odb::access::object_traits_impl::image_type" in "const odb::access::composite_value_traits::image_type" nicht m"glich TestiAll-odb-pgsql.cpp(183): note: Kein benutzerdefinierter Konvertierungsoperator verf?gbar, der diese Konvertierung durchf?hren kann, oder der Operator kann nicht aufgerufen werden TestiAll-odb-pgsql.cpp(191): error C2665: "odb::access::composite_value_traits::init": Durch keine der 2 ?berladungen konnten alle Argumenttypen konvertiert werden. TestiAll-odb-pgsql.h(330): note: kann "void odb::access::composite_value_traits::init(odb::access::composite_value_traits::value_type &,const odb::access::composite_value_traits::image_type &,odb::database *)" sein TestiAll-odb-pgsql.h(325): note: oder "bool odb::access::composite_value_traits::init(odb::access::composite_value_traits::image_type &,const odb::access::composite_value_traits::value_type &,odb::pgsql::statement_kind)" TestiAll-odb-pgsql.cpp(191): note: bei Anpassung der Argumentliste "(odb::access::object_traits::id_type, const odb::access::object_traits_impl::image_type, odb::database *)" // ----------- TestiAll.h ---------------- struct testi2; #pragma db object struct testi { testi () {} testi (int asdf, const std::string& desc) : asdf(asdf), description(desc) {} #pragma db inverse(id.asdf) std::vector > children; #pragma db id int asdf; std::string description; }; #pragma db object struct testi2 { testi2() : parent(new testi()) {} testi2(int asdf, int qwer, const std::string &m) : parent(new testi(asdf, "")), qwer(qwer), moredata(m) {} #pragma db transient std::shared_ptr parent; #pragma db transient int qwer; #pragma db value struct id_type { id_type() {} id_type(int asdf_, int qwer_) : asdf(asdf_), qwer(qwer_) {} #pragma db points_to(testi) int asdf; int qwer; }; std::string moredata; #pragma db member(id) virtual(id_type) id column("") \ get (id_type(this.parent->asdf, this.qwer)) \ set (this.parent = std::shared_ptr<::testi>(new ::testi((?).asdf, "")); this.qwer = (?).qwer) }; inline bool operator < (const testi2::id_type &l, const testi2::id_type &r) { if (l.asdf != r.asdf) return l.asdf < r.asdf; return l.qwer < r.qwer; } From Tschoche.Jonas at ddv-mediengruppe.de Tue Oct 15 15:17:49 2019 From: Tschoche.Jonas at ddv-mediengruppe.de (Tschoche.Jonas@ddv-mediengruppe.de) Date: Wed Oct 16 02:03:27 2019 Subject: [odb-users] Compile Problem with odd and mysql Message-ID: <8C400EA4-4678-41CB-96C5-952FF73641C0@ddv-mediengruppe.de> Hello, i have a problem with odb. I compiled all components with build2 on MacOS Mojave (odb, libodb, libodb-mysql, libodb-sqlite, libodb-boost, ?). I tried to compile an example with odb with following command: odb -d mysql --generate-query --generate-schema --schema-format embedded --std c++11 --output-dir /Users /DEV/Examples/OdbCmake/cmake-build-debug/odb_gen --hxx-suffix .h --ixx-suffix _inline.h --cxx-suffix .cpp --odb-file-suffix _odb -I/usr/local/include -I/usr/local/Cellar/mysql-connector-c/6.1.11/include -I/usr/local/include/odb/mysql person.h It working, but when I compile the project with CMAKE (example from github: https://github.com/BtbN/OdbCmake/) then I get a compile error: In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.cpp:9: In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.h:107: /usr/local/include/odb/mysql/binding.hxx:28:16: error: unknown type name 'MYSQL_BIND'; did you mean 'MYSQL_TIME'? binding (MYSQL_BIND* b, std::size_t n) ^ /usr/local/include/mysql/mysql_time.h:69:3: note: 'MYSQL_TIME' declared here } MYSQL_TIME; ^ In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.cpp:9: In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.h:107: /usr/local/include/odb/mysql/binding.hxx:33:7: error: unknown type name 'MYSQL_BIND'; did you mean 'MYSQL_TIME'? MYSQL_BIND* bind; ^ /usr/local/include/mysql/mysql_time.h:69:3: note: 'MYSQL_TIME' declared here } MYSQL_TIME; ^ I had include the mysql libs, but the compiler don?t know ?mysql?. My CMAKE file: cmake_minimum_required(VERSION 2.8.12) project(OdbCMake) set(CMAKE_EXE_LINKER_FLAGS -all_load) # macos set(CMAKE_VERBOSE_MAKEFILE ON) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules") set(MYSQL_FIND_QUIETLY OFF ) find_package(MySQL) find_package(SQLite3) find_package(ODB REQUIRED COMPONENTS sqlite mysql OPTIONAL_COMPONENTS pgsql) include(${ODB_USE_FILE}) set(OdbCMake_SOURCES driver.cpp database.h) set(OdbCMake_ODB_HEADERS person.h) set(ODB_COMPILE_DEBUG ON) odb_compile(OdbCMake_SOURCES FILES ${OdbCMake_ODB_HEADERS} DB mysql GENERATE_QUERY GENERATE_SCHEMA SCHEMA_FORMAT embedded STANDARD c++11 INCLUDE ${ODB_INCLUDE_DIRS} ${MYSQL_INCLUDE_DIR} ${ODB_MYSQL_INCLUDE_DIRS}/odb/mysql) message("ODB_INCLUDE_DIRS: ${ODB_INCLUDE_DIRS}") message("OUTPUT: ${ODB_COMPILE_OUTPUT_DIR}") message("") message("MYSQL_LIB: ${MYSQL_LIBRARIES}") message("MySQL_INCLUDE_DIRS: ${MYSQL_INCLUDE_DIR}") message("") message("MYSQL_LIB (ODB): ${ODB_MYSQL_LIBRARIES}") message("MySQL_INCLUDE_DIRS (ODB): ${ODB_MYSQL_INCLUDE_DIRS}") message("") message("MYSQL_LIB: ${MYSQL_LIBRARIES}") message("MySQL_INCLUDE_DIRS: ${MYSQL_INCLUDE_DIR}") message("") message("LIBSQLLITE: ${SQLite3_LIBRARIES}") message("LIBSQLLITE_INCLUDE_DIRS: ${SQLite3_INCLUDE_DIRS}") message("ODB:") message(${OdbCMake_ODB_HEADERS}) add_executable(odbcmake ${OdbCMake_SOURCES} ${OdbCMake_ODB_HEADERS}) target_link_libraries(odbcmake ${MYSQL_LIBRARIES} ${ODB_LIBRARIES} ${ODB_MYSQL_LIBRARIES} ) target_include_directories(odbcmake PUBLIC ${MYSQL_INCLUDE_DIR} PRIVATE ${ODB_INCLUDE_DIRS} ${ODB_MYSQL_INCLUDE_DIRS} ${ODB_COMPILE_OUTPUT_DIR} ) target_compile_definitions(odbcmake PRIVATE DATABASE_MYSQL) The Source Files are from Github: https://github.com/BtbN/OdbCmake/ --- When I try to compile the official example then I get also a build error: Making all in access /Applications/Xcode.app/Contents/Developer/usr/bin/make all-am depbase=`echo driver.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\ g++ -DHAVE_CONFIG_H -I'.' -I'.' -DDATABASE_SQLITE -I/usr/local/include -g -O2 -D_THREAD_SAFE -MT driver.o -MD -MP -MF $depbase.Tpo -c -o driver.o driver.cxx &&\ mv -f $depbase.Tpo $depbase.Po In file included from driver.cxx:7: In file included from /usr/local/include/odb/database.hxx:23: /usr/local/include/odb/traits.hxx:138:22: error: implicit instantiation of undefined template 'odb::pointer_traits >' typedef typename pointer_traits::const_pointer_type const_pointer_type; ^ /usr/local/include/odb/database.ixx:160:19: note: in instantiation of template class 'odb::object_traits' requested here inline typename object_traits::id_type database:: ^ driver.cxx:30:11: note: while substituting deduced template arguments into function template 'persist' [with T = person] db->persist (john); ^ /usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here class pointer_traits; ^ driver.cxx:39:21: warning: lookup of 'query' in member access expression is ambiguous; using member of 'odb::database' [-Wambiguous-member-template] result r (db->query ()); ^ /usr/local/include/odb/database.ixx:557:3: note: lookup in the object type 'odb::database' refers here query (bool cache) ^ /usr/local/include/odb/query.hxx:110:9: note: lookup from the current scope refers here class query; ^ In file included from driver.cxx:13: In file included from ./person-odb.hxx:32: /usr/local/include/odb/simple-object-result.hxx:149:14: error: implicit instantiation of undefined template 'odb::pointer_traits >' typename pointer_traits::guard guard_; ^ /usr/local/include/odb/details/shared-ptr/base.txx:58:53: note: in instantiation of template class 'odb::object_result_impl' requested here std::size_t A = sizeof (bits::test (reinterpret_cast (0)))> ^ /usr/local/include/odb/details/shared-ptr.hxx:20:48: note: in instantiation of default argument for 'counter_type >' required here private bits::counter_ops::r, X> ^~~~~~~~~~~~~~~ /usr/local/include/odb/result.hxx:234:43: note: in instantiation of template class 'odb::details::shared_ptr >' requested here details::shared_ptr impl_; ^ driver.cxx:39:21: note: in instantiation of template class 'odb::result' requested here result r (db->query ()); ^ /usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here class pointer_traits; ^ In file included from driver.cxx:7: In file included from /usr/local/include/odb/database.hxx:27: In file included from /usr/local/include/odb/prepared-query.hxx:12: In file included from /usr/local/include/odb/result.hxx:16: In file included from /usr/local/include/odb/details/shared-ptr.hxx:11: In file included from /usr/local/include/odb/details/shared-ptr/base.hxx:128: /usr/local/include/odb/details/shared-ptr/base.txx:58:53: error: cannot initialize a parameter of type 'odb::details::shared_base *' with an rvalue of type 'odb::object_result_impl *' std::size_t A = sizeof (bits::test (reinterpret_cast (0)))> ^~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/odb/details/shared-ptr.hxx:20:48: note: in instantiation of default argument for 'counter_type >' required here private bits::counter_ops::r, X> ^~~~~~~~~~~~~~~ /usr/local/include/odb/result.hxx:234:43: note: in instantiation of template class 'odb::details::shared_ptr >' requested here details::shared_ptr impl_; ^ driver.cxx:39:21: note: in instantiation of template class 'odb::result' requested here result r (db->query ()); ^ /usr/local/include/odb/details/shared-ptr/base.txx:55:35: note: passing argument to parameter here meta::yes test (shared_base*); ^ In file included from driver.cxx:7: In file included from /usr/local/include/odb/database.hxx:23: /usr/local/include/odb/traits.hxx:158:22: error: implicit instantiation of undefined template 'odb::pointer_traits >' typedef typename pointer_traits::const_pointer_type const_pointer_type; ^ /usr/local/include/odb/database.hxx:537:5: note: in instantiation of template class 'odb::object_traits' requested here typename object_traits::id_type ^ /usr/local/include/odb/database.ixx:170:12: note: while substituting explicitly-specified template arguments into function template 'persist_' return persist_ (obj); ^ driver.cxx:30:11: note: in instantiation of function template specialization 'odb::database::persist' requested here db->persist (john); ^ /usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here class pointer_traits; ^ In file included from driver.cxx:7: In file included from /usr/local/include/odb/database.hxx:651: /usr/local/include/odb/database.ixx:170:12: error: no matching member function for call to 'persist_' return persist_ (obj); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ driver.cxx:30:11: note: in instantiation of function template specialization 'odb::database::persist' requested here db->persist (john); ^ /usr/local/include/odb/database.hxx:542:5: note: candidate function template not viable: no known conversion from 'const person' to 'const typename object_traits::pointer_type' (aka 'const int') for 1st argument persist_ (const typename object_traits::pointer_type&); ^ /usr/local/include/odb/database.hxx:538:5: note: candidate template ignored: substitution failure [with T = const person, DB = odb::id_common] persist_ (T&); ^ /usr/local/include/odb/database.hxx:546:5: note: candidate function template not viable: requires 3 arguments, but 1 was provided persist_ (I, I, bool); ^ /usr/local/include/odb/database.hxx:550:5: note: candidate function template not viable: requires 4 arguments, but 1 was provided persist_ (I, I, bool, details::meta::no ptr); ^ /usr/local/include/odb/database.hxx:554:5: note: candidate function template not viable: requires 4 arguments, but 1 was provided persist_ (I, I, bool, details::meta::yes ptr); ^ In file included from driver.cxx:7: In file included from /usr/local/include/odb/database.hxx:23: /usr/local/include/odb/traits.hxx:187:22: error: implicit instantiation of undefined template 'odb::pointer_traits >' typedef typename pointer_traits::const_pointer_type const_pointer_type; ^ /usr/local/include/odb/database.txx:38:5: note: in instantiation of template class 'odb::object_traits_impl' requested here object_traits::persist (*this, obj); ^ /usr/local/include/odb/database.ixx:163:12: note: in instantiation of function template specialization 'odb::database::persist_' requested here return persist_ (obj); ^ driver.cxx:31:11: note: in instantiation of function template specialization 'odb::database::persist' requested here db->persist (jane); ^ /usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here class pointer_traits; ^ In file included from driver.cxx:7: In file included from /usr/local/include/odb/database.hxx:652: /usr/local/include/odb/database.txx:38:18: error: incomplete definition of type 'odb::object_traits_impl' object_traits::persist (*this, obj); ~~~~~~~~~~~~~^~ /usr/local/include/odb/database.ixx:163:12: note: in instantiation of function template specialization 'odb::database::persist_' requested here return persist_ (obj); ^ driver.cxx:31:11: note: in instantiation of function template specialization 'odb::database::persist' requested here db->persist (jane); ^ In file included from driver.cxx:7: In file included from /usr/local/include/odb/database.hxx:23: /usr/local/include/odb/traits.hxx:187:22: error: implicit instantiation of undefined template 'odb::pointer_traits >' typedef typename pointer_traits::const_pointer_type const_pointer_type; ^ /usr/local/include/odb/query.hxx:89:22: note: in instantiation of template class 'odb::object_traits_impl' requested here typedef typename object_traits_impl::query_base_type base_type; ^ /usr/local/include/odb/query.hxx:104:26: note: in instantiation of template class 'odb::query_selector_impl' requested here struct query_selector: query_selector_impl::kind> ^ /usr/local/include/odb/sqlite/query.hxx:1597:25: note: in instantiation of template class 'odb::query_selector' requested here public query_selector::columns_type ^ /usr/local/include/odb/sqlite/query.hxx:1667:46: note: in instantiation of template class 'odb::sqlite::query' requested here class query: public sqlite::query ^ /usr/local/include/odb/database.ixx:559:22: note: in instantiation of template class 'odb::query' requested here return query (odb::query (), cache); ^ driver.cxx:39:21: note: in instantiation of function template specialization 'odb::database::query' requested here result r (db->query ()); ^ /usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here class pointer_traits; ^ In file included from driver.cxx:13: In file included from ./person-odb.hxx:32: In file included from /usr/local/include/odb/simple-object-result.hxx:16: /usr/local/include/odb/object-result.hxx:108:14: error: implicit instantiation of undefined template 'odb::pointer_traits >' return pointer_traits::get_ptr (this->res_->current ()); ^ driver.cxx:42:18: note: in instantiation of member function 'odb::result_iterator::operator->' requested here cout << i->getFirst () << ' ' ^ /usr/local/include/odb/pointer-traits.hxx:28:9: note: template is declared here class pointer_traits; ^ In file included from driver.cxx:13: In file included from ./person-odb.hxx:32: In file included from /usr/local/include/odb/simple-object-result.hxx:16: /usr/local/include/odb/object-result.hxx:108:28: error: incomplete definition of type 'odb::pointer_traits >' return pointer_traits::get_ptr (this->res_->current ()); ~~~~~~~~~~~~~~^~ 1 warning and 10 errors generated. make[3]: *** [driver.o] Error 1 make[2]: *** [all] Error 2 make[1]: *** [all-recursive] Error 1 make: *** [all] Error 2 I configured with: ./configure --with-database=sqlite CPPFLAGS=-I/usr/local/include LDFLAGS=-L/opt/local/lib ODBCPPFLAGS="-I/usr/local/include" From boris at codesynthesis.com Wed Oct 16 10:55:12 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 16 11:01:06 2019 Subject: [odb-users] One-to-many bidirectional relationship without intermediary table In-Reply-To: References: Message-ID: Mocnik Marko writes: > What am I doing wrong? This has to do with the ordering of things due to circular relationship. The composite id type of testi2 must be known before testi definition. The below version compiles fine for me. You could also make it work (in this case) by swapping the order of testi and testi2 definitions. //----------------------------------------- #include #include #include struct testi; struct testi2; #pragma db value struct testi2_id_type { testi2_id_type() {} testi2_id_type(int asdf_, int qwer_) : asdf(asdf_), qwer(qwer_) {} #pragma db points_to(testi) int asdf; int qwer; }; #pragma db object struct testi { testi () {} testi (int asdf, const std::string& desc) : asdf(asdf), description(desc) {} #pragma db inverse(id.asdf) std::vector > children; #pragma db id int asdf; std::string description; }; #pragma db object struct testi2 { testi2() : parent(new testi()) {} testi2(int asdf, int qwer, const std::string &m) : parent(new testi(asdf, "")), qwer(qwer), moredata(m) {} #pragma db transient std::shared_ptr parent; #pragma db transient int qwer; std::string moredata; #pragma db member(id) virtual(testi2_id_type) id column("") \ get (id_type(this.parent->asdf, this.qwer)) \ set (this.parent = std::shared_ptr<::testi>(new ::testi((?).asdf, "")); this.qwer = (?).qwer) }; inline bool operator < (const testi2_id_type &l, const testi2_id_type &r) { if (l.asdf != r.asdf) return l.asdf < r.asdf; return l.qwer < r.qwer; } //----------------------------------------- From boris at codesynthesis.com Wed Oct 16 10:59:20 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 16 11:05:13 2019 Subject: [odb-users] Compile Problem with odd and mysql In-Reply-To: <8C400EA4-4678-41CB-96C5-952FF73641C0@ddv-mediengruppe.de> References: <8C400EA4-4678-41CB-96C5-952FF73641C0@ddv-mediengruppe.de> Message-ID: Tschoche.Jonas@ddv-mediengruppe.de writes: > Hello, > > i have a problem with odb. I compiled all components with build2 on MacOS Mojave > (odb, libodb, libodb-mysql, libodb-sqlite, libodb-boost, ?). > > I tried to compile an example with odb with following command: > > odb -d mysql --generate-query --generate-schema --schema-format embedded --std c++11 --output-dir /Users /DEV/Examples/OdbCmake/cmake-build-debug/odb_gen --hxx-suffix .h --ixx-suffix _inline.h --cxx-suffix .cpp --odb-file-suffix _odb -I/usr/local/include -I/usr/local/Cellar/mysql-connector-c/6.1.11/include -I/usr/local/include/odb/mysql person.h > > It working, but when I compile the project with CMAKE (example from github: https://github.com/BtbN/OdbCmake/) then I get a compile error: > > In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.cpp:9: > In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.h:107: > /usr/local/include/odb/mysql/binding.hxx:28:16: error: unknown type name 'MYSQL_BIND'; did you mean 'MYSQL_TIME'? > binding (MYSQL_BIND* b, std::size_t n) Yes, this is a know issue that has been fixed and will be published to cppget.org with the next release of build2. In the meantime, you can either get everything from stage: https://build2.org/community.xhtml#stage Or follow this instructions to fix-up things from cppget.org: https://www.codesynthesis.com/pipermail/odb-users/2019-September/004335.html From Tschoche.Jonas at ddv-mediengruppe.de Thu Oct 17 03:58:51 2019 From: Tschoche.Jonas at ddv-mediengruppe.de (Tschoche.Jonas@ddv-mediengruppe.de) Date: Thu Oct 17 06:53:35 2019 Subject: [odb-users] Compile Problem with odd and mysql In-Reply-To: References: <8C400EA4-4678-41CB-96C5-952FF73641C0@ddv-mediengruppe.de> Message-ID: <007012DE-6295-45D1-8AB1-A94770EF688E@ddv-mediengruppe.de> Thank you for your fast reply and your help. I was pretty desperate. ?Am 16.10.19, 16:59 schrieb "Boris Kolpackov" : Tschoche.Jonas@ddv-mediengruppe.de writes: > Hello, > > i have a problem with odb. I compiled all components with build2 on MacOS Mojave > (odb, libodb, libodb-mysql, libodb-sqlite, libodb-boost, ?). > > I tried to compile an example with odb with following command: > > odb -d mysql --generate-query --generate-schema --schema-format embedded --std c++11 --output-dir /Users /DEV/Examples/OdbCmake/cmake-build-debug/odb_gen --hxx-suffix .h --ixx-suffix _inline.h --cxx-suffix .cpp --odb-file-suffix _odb -I/usr/local/include -I/usr/local/Cellar/mysql-connector-c/6.1.11/include -I/usr/local/include/odb/mysql person.h > > It working, but when I compile the project with CMAKE (example from github: https://github.com/BtbN/OdbCmake/) then I get a compile error: > > In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.cpp:9: > In file included from /Users/DEV/Examples/OdbCmake/cmake-build-debug/odb_gen/person_odb.h:107: > /usr/local/include/odb/mysql/binding.hxx:28:16: error: unknown type name 'MYSQL_BIND'; did you mean 'MYSQL_TIME'? > binding (MYSQL_BIND* b, std::size_t n) Yes, this is a know issue that has been fixed and will be published to cppget.org with the next release of build2. In the meantime, you can either get everything from stage: https://build2.org/community.xhtml#stage Or follow this instructions to fix-up things from cppget.org: https://www.codesynthesis.com/pipermail/odb-users/2019-September/004335.html From javier.gutierrez at web.de Fri Oct 18 05:31:39 2019 From: javier.gutierrez at web.de (Javier Gutierrez) Date: Fri Oct 18 05:37:46 2019 Subject: [odb-users] Pointer error with query_one but not with query_value Message-ID: <011901d58596$d88374a0$898a5de0$@gutierrez@web.de> Hi there, I modified a bit the example "view" to prove my error. So I generate the API for the view employee_count (employee.hxx) with the flag --default-pointer std::shared_ptr Then in driver.cxx: If I use following int count = db->query_value (query::last == "Doe").count; it gets compiled successfully: If I use following int count = db->query_one (query::last == "Doe")->count; I get the error: error: cannot convert 'odb::view_traits::pointer_type {aka std::shared_ptr}' to 'pointer_type {aka employee_count*}' in initialization So I changed my code to use query_value instead. But out of curiosity any idea what is wrong with the code using query_one? Regards, Javier From yohuang at nvidia.com Thu Oct 17 10:34:49 2019 From: yohuang at nvidia.com (Justin Huang) Date: Fri Oct 18 09:59:46 2019 Subject: [odb-users] Load Sqlite DB Message-ID: Hi Boris, I saved a sqlite3 db in one program, and later I tried to load the db back in second program. The code snippet of the load program is shown below, If I call create_schema after create_database, then the query result is empty. If I comment out create_schema, then odb reports '1: no such table: Module' error. I confirmed the saved db is expected using sqlite3 to open it and run 'select * from Module'; So what's the right way to open an existing DB? My understanding is to comment create_schema in load program. Thanks, Justin // load an existing DB db = std::unique_ptr(create_database (argc, argv)); { connection_ptr c (db->connection ()); c->execute ("PRAGMA foreign_keys=OFF"); transaction t (c->begin ()); schema_catalog::create_schema (*db); t.commit (); c->execute ("PRAGMA foreign_keys=ON"); } typedef odb::result r; r all_modules (db->query ()); for (auto i: all_modules) { std::cout << "name: " << i->name() << std:endl; } t.commit(); ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- From yohuang at nvidia.com Thu Oct 17 10:54:40 2019 From: yohuang at nvidia.com (Justin Huang) Date: Fri Oct 18 09:59:46 2019 Subject: [odb-users] RE: Load Sqlite DB In-Reply-To: References: Message-ID: Hmm, please ignore it. I realized that the argc/argv was not correctly setup. After fixing it, it works now. From: Justin Huang Sent: Thursday, October 17, 2019 10:35 PM To: odb-users@codesynthesis.com Subject: Load Sqlite DB Hi Boris, I saved a sqlite3 db in one program, and later I tried to load the db back in second program. The code snippet of the load program is shown below, If I call create_schema after create_database, then the query result is empty. If I comment out create_schema, then odb reports '1: no such table: Module' error. I confirmed the saved db is expected using sqlite3 to open it and run 'select * from Module'; So what's the right way to open an existing DB? My understanding is to comment create_schema in load program. Thanks, Justin // load an existing DB db = std::unique_ptr(create_database (argc, argv)); { connection_ptr c (db->connection ()); c->execute ("PRAGMA foreign_keys=OFF"); transaction t (c->begin ()); schema_catalog::create_schema (*db); t.commit (); c->execute ("PRAGMA foreign_keys=ON"); } typedef odb::result r; r all_modules (db->query ()); for (auto i: all_modules) { std::cout << "name: " << i->name() << std:endl; } t.commit(); ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- From naveen.akkapeddi at apex.ai Fri Oct 18 15:33:14 2019 From: naveen.akkapeddi at apex.ai (Naveen Akkapeddi) Date: Sat Oct 19 05:00:23 2019 Subject: [odb-users] Compiling libodb-mysql fails on aarch64 Message-ID: Hi, I am running into an issue building the plugin `libodb-mysql` on `aarch64` architecture. It appears the version of SSL that's included doesn't have configuration files for `aarch64`. Here is the error output when running `bpkg build libodb-mysql` In file included from /home/ubuntu/odb-build/odb-gcc-X/libcrypto-1.1.1+4/libcrypto/downstream/internal/dso_conf.h:12:0, from /home/ubuntu/odb-build/odb-gcc-X/libcrypto-1.1.1+4/libcrypto/crypto/init.c:27: /home/ubuntu/odb-build/odb-gcc-X/libcrypto-1.1.1+4/libcrypto/downstream/internal/dso_conf/platform.h:53:6: error: #error unknown architecture # error unknown architecture ^~~~~ How do I proceed? Can I drop in upstream openSSL config for ARM64? Thanks, -- Naveen Akkapeddi Sr. DevOps Engineer m: (408) 874-5314 Apex.AI www.apex.ai From boris at codesynthesis.com Mon Oct 21 11:47:08 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 21 11:47:23 2019 Subject: [odb-users] Compiling libodb-mysql fails on aarch64 In-Reply-To: References: Message-ID: Naveen Akkapeddi writes: > I am running into an issue building the plugin `libodb-mysql` on `aarch64` > architecture. > It appears the version of SSL that's included doesn't have configuration > files for `aarch64`. > Here is the error output when running `bpkg build libodb-mysql` > > In file included from > /home/ubuntu/odb-build/odb-gcc-X/libcrypto-1.1.1+4/libcrypto/downstream/internal/dso_conf.h:12:0, > from > /home/ubuntu/odb-build/odb-gcc-X/libcrypto-1.1.1+4/libcrypto/crypto/init.c:27: > /home/ubuntu/odb-build/odb-gcc-X/libcrypto-1.1.1+4/libcrypto/downstream/internal/dso_conf/platform.h:53:6: > error: #error unknown architecture > # error unknown architecture > ^~~~~ > > How do I proceed? Can I drop in upstream openSSL config for ARM64? You can certainly try (there is a description[1] of how they are ported) and if you succeed, please send it along so that we can include it into the package. If that doesn't work, you should be able to fallback to the system- installed openssl: bpkg build libodb-mysql ?sys:libcrypto ?sys:libssl [1] https://github.com/build2-packaging/openssl/blob/master/README-DEV From moni.idzik at gmail.com Mon Oct 28 10:01:09 2019 From: moni.idzik at gmail.com (Monika Idzik) Date: Mon Oct 28 10:02:03 2019 Subject: [odb-users] Schema evolution on existing database Message-ID: Hi, I'm trying to add new columns to existing table in a MySQL database. I followed the instructions regarding schema evolution, generating the code: odb::core::schema_version v(m_db->schema_version()); odb::core::schema_version bv(odb::core::schema_catalog::base_version(*m_db)); odb::core::schema_version cv(odb::core::schema_catalog::current_version(*m_db)); if (v == 0) { odb::core::transaction t(m_db->begin()); odb::core::schema_catalog::create_schema(*m_db); t.commit(); } else if (v < cv) { if (v < bv) { std::cout << "Error: migration from this version is no longer supported." << std::endl; } for (v = odb::core::schema_catalog::next_version(*m_db, v); v <= cv; v = odb::core::schema_catalog::next_version(*m_db, v)) { odb::core::transaction t(m_db->begin()); odb::core::schema_catalog::migrate_schema_pre(*m_db, v); // Data migration goes here. odb::core::schema_catalog::migrate_schema_post(*m_db, v); t.commit(); } } else if (v > cv) { std::cout << "Error: old application trying to access new database." << std::endl; } } I also added #pragma db model version(1,1) It all works well: when I'm changing to version (1,2) and adding new columns. However, I already have data in my current database that was created without model versions and schema evolution code: this means that when I'm adding the above code, the existing data is being removed (I assume while doing odb::core::schema_catalog::create_schema(*m_db);) Is there a way to add new columns to the existing database (so changing database schema) without losing existing data in the database? Thanks, Monika From per.edin at sequence-point.se Sat Oct 26 20:58:35 2019 From: per.edin at sequence-point.se (Per Edin) Date: Mon Oct 28 10:18:30 2019 Subject: [odb-users] Inverse side of std::map with object pointer as key Message-ID: Hi! I'm having some trouble getting an inverse pragma to work for the following code snippet, see the comment NOT LOADED. Locations in item is always empty when I load an item from the database. Am I missing some options? After digging around and tracing SQL I found that ODB tries to load item::locations by looking at the value column in locations_items table, i.e. the value of the std::map. I need it to look at the key of the map. Is this possible somehow? Any help is much appreciated. Kind regards, Per Edin #ifndef schema_hxx_ #define schema_hxx_ #include namespace application::world { // Item // class location; class item : public std::enable_shared_from_this< item > { size_t id; string ext_id; string name; vector< weak_ptr< location > > locations; // NOT LOADED }; #pragma db object(item) table("items") session #pragma db member(item::id) column("id") id auto #pragma db member(item::ext_id) column("ext_id") unique not_null #pragma db member(item::name) column("name") unique not_null #pragma db member(item::locations) inverse(items) // Location // class location : public std::enable_shared_from_this< location > { size_t id; string ext_id; string name; map< shared_ptr< item >, long > items; // loads fine }; #pragma db object(location) table("locations") sessions #pragma db member(location::id) column("id") id auto #pragma db member(location::ext_id) column("ext_id") unique not_null #pragma db member(location::name) column("name") unique not_null #pragma db member(location::items) column("items") value_not_null } #endif From boris at codesynthesis.com Mon Oct 28 10:33:08 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 28 10:33:43 2019 Subject: [odb-users] Inverse side of std::map with object pointer as key In-Reply-To: References: Message-ID: Per Edin writes: > I'm having some trouble getting an inverse pragma to work for the > following code snippet, see the comment NOT LOADED. > > vector< weak_ptr< location > > locations; // NOT LOADED > > map< shared_ptr< item >, long > items; We actually did some work to allow using object pointers as map keys in this commit: https://git.codesynthesis.com/cgit/odb/odb/commit/?id=4c87055fbbf4b36224cc4003cc9ae38023390400 Just to confirm you are using something reasonably recent from the 2.5.0 beta series, correct? If so, perhaps we didn't handle the inverse part of things. Feel free to dig around the code and suggest a fix/patch ;-). From boris at codesynthesis.com Mon Oct 28 10:40:18 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 28 10:40:54 2019 Subject: [odb-users] Schema evolution on existing database In-Reply-To: References: Message-ID: Monika Idzik writes: > However, I already have data in my current database that was created > without model versions and schema evolution code: this means that when I'm > adding the above code, the existing data is being removed (I assume while > doing odb::core::schema_catalog::create_schema(*m_db);) Probably what happens is the ODB schema evolution machinery thinks the schema does not exist since there is no schema_version table in it. There is actually a discussion of this situation in Section 13.2, "Schema Migration": "Note also that above we mentioned that the schema creation statements (person.sql) create the schema_version table. This means that if we enable schema evolution support in the middle of a project, then we could already have existing databases that don't include this table. As a result, ODB will not be able to handle migrations for such databases unless we manually add the schema_version table and populate it with the correct version information. For this reason, it is highly recommended that you consider whether to use schema evolution and, if so, enable it from the beginning of your project." > Is there a way to add new columns to the existing database (so changing > database schema) without losing existing data in the database? The above paragraph suggests a solution: create and populate the schema_version table manually. From yohuang at nvidia.com Wed Oct 30 22:40:29 2019 From: yohuang at nvidia.com (Justin Huang) Date: Thu Oct 31 09:20:04 2019 Subject: [odb-users] How to cache the queried object pointer? Message-ID: Hi, I'd like to load sqlite3 DB back, construct C++ objects, and save the object pointers for later usage. I have 3 Module entries in the Module table, the code below is used. It is weird that the 'ptr' of the 1st Module is destructed before looping the 2nd Module, but 2nd/3rd Module ptr are not destructed. I wonder how should we cache the queried object pointers for later use? I don't want to create new Module using copy constructor from the result::iterator, because the Modules can have cross references (I mean point to each other) in class definition and creating new Module objects would require updating all the cross references. Thanks, Justin class DB { public: void load_db(int argc, char* argv[]); private: std::vector modules; }; void DB::load_db(int argc, char* argv[]) { try { session s; db = std::unique_ptr(create_database (argc, argv)); // load all modules in Module table back into C++ objects { odb::transaction t (db->begin()); typedef odb::result result; result all_modules (db->query ()); int count = 0; for (result::iterator i(all_modules.begin()); i != all_modules.end(); ++i) { auto ptr = i.operator->(); modules.push_back(ptr); } } } } ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- From icewill9999 at vip.qq.com Thu Oct 31 03:56:51 2019 From: icewill9999 at vip.qq.com (=?gb18030?B?srvD99Xmz+A=?=) Date: Thu Oct 31 09:20:04 2019 Subject: [odb-users] Is that possible to order the child objects based on some specific column Message-ID: Hi, i searched the mailing list but no answer found for this issue. Say i have two tables, A and B of 1:N relationship, B is eager loaded. #pragma db object class A { ........  vector References: Message-ID: On Mon, Oct 28, 2019 at 3:33 PM Boris Kolpackov wrote: > We actually did some work to allow using object pointers as map keys > in this commit: > > https://git.codesynthesis.com/cgit/odb/odb/commit/?id=4c87055fbbf4b36224cc4003cc9ae38023390400 > > Just to confirm you are using something reasonably recent from the > 2.5.0 beta series, correct? > > If so, perhaps we didn't handle the inverse part of things. Feel free > to dig around the code and suggest a fix/patch ;-). I'm using version 2.5.0-b.15. The "object pointers as map key" feature does work. It's the inverse that doesn't. The generated SQL looks at the value column instead of the key column, which happened to run fine since my value type was of integer type (long). I'm not too familiar with the inner workings of ODB, but I can surely have a look at it. :-) // Per From moni.idzik at gmail.com Thu Oct 31 10:36:44 2019 From: moni.idzik at gmail.com (Monika Idzik) Date: Thu Oct 31 10:37:47 2019 Subject: [odb-users] Schema evolution on existing database In-Reply-To: References: Message-ID: Hi, ok, your suggested approach helped, I was able to add new columns without overwriting previous results, thanks! The above paragraph suggests a solution: create and populate the > schema_version table manually. >