From finjulhich at gmail.com Wed Jul 1 14:45:31 2015 From: finjulhich at gmail.com (MM) Date: Wed Jul 1 14:45:39 2015 Subject: [odb-users] base class, derived, separate headers and derived references base In-Reply-To: References: Message-ID: On 26 June 2015 at 16:32, Boris Kolpackov wrote: > Hi, > > MM writes: > > > Is this something that may have been addressed after some particular > > version? > > > > I run 2.3.0 > > I think so. Why don't you try 2.4.0? > > Boris > After all, perhaps i'm having a different issue: dir1/A.hpp =================== namespace NS { struct A { ... ...const T* underlying; ... }; struct selector { int id; int type; }; void set_A_underlying(A&, const selector&); } dir1_odb/A.hpp ==================== #include namespace NS { #pragma db value(selector) definition #pragma db object(A) table("A") definition #pragma db member(A::underlying) transient #pragma db member(A::ulid) virtual(selector) \ get( selector(this.underlying->type(), this.underlying->id)) \ set(set_A_underlying (this,(?))) } Calling odb on dir1_odb/A.hpp with the proper options generates successfully the A.hxx A.ixx A.cxx but compiling with that generates this error: error: ?image_type? in ?class odb::access::composite_value_traits? does not name a type It looks like no traits get generated for selector. Rds, From selection989 at gmail.com Wed Jul 1 22:29:18 2015 From: selection989 at gmail.com (Teererai Marange) Date: Thu Jul 2 14:03:54 2015 Subject: [odb-users] Using --generate-schema does not output sql file when using sqlite Message-ID: I am working with the hello world example given on the tutorial pages and am trying to work through all the steps. When I enter odb -d sqlite --generate-query --generate-schema person.hxx no sql file is generated and so I am not able to create a database schema on sqlite. How do I proceed in such a situation? -- Regards, Teererai Marange Ph: 021521987 From dieter.govaerts at bricsys.com Thu Jul 2 08:15:54 2015 From: dieter.govaerts at bricsys.com (dieter.govaerts@bricsys.com) Date: Thu Jul 2 14:03:54 2015 Subject: [odb-users] Templated view class Message-ID: <1435839354.38887447@apps.rackspace.com> Hello, If I define my view class as follows: #pragma db view object(Composition) struct CompositionNameView { String name; }; it works as expected in the function: template<> String getName(odb::database *db, unsigned int id) { typedef odb::query< CompositionNameView > Query; odb::result< CompositionNameView > r(db->query< CompositionNameView >(Query::id == id)); CompositionNameView nameView; if (!r.empty()) r.begin().load(nameView); return nameView.name; } If I rewrite the view class in a templated form, that is equivalent in my opinion, as: template struct ObjectNameView { String name; }; typedef ObjectNameView CompositionNameView; #pragma db view(CompositionNameView) object(Composition) then the odb compiler succeeds but the (visual) c++ compiler fails: 1> libodb\include\odb/query.hxx(105): error C2504: 'odb::query_selector_impl' : base class undefined 1> with 1> [ 1> T=bim_lib::CompositionNameView, 1> DB=id_common, 1> kind=class_other 1> ] 1> ... 1> libodb\include\odb/result.hxx(76): error C2504: 'odb::result_base' : base class undefined 1> with 1> [ 1> T=bim_lib::CompositionNameView, 1> kind=class_other 1> ] The point is of course to generalize the getName function so I don't have to write it for each object type: template String getName(odb::database *db, unsigned int id) { typedef odb::query< ObjectNameView > Query; odb::result< ObjectNameView > r(db->query< ObjectNameView >(Query::id == id)); ObjectNameView nameView; if (!r.empty()) r.begin().load(nameView); return nameView.name; } Can I use templated view classes and how? Thanks in advance. Dieter Govaerts From selection989 at gmail.com Thu Jul 2 08:34:15 2015 From: selection989 at gmail.com (Teererai Marange) Date: Thu Jul 2 14:03:54 2015 Subject: [odb-users] using the odb command when one of the c files is generated by makefile Message-ID: I have implemented a version of bfs which will run on multiple abstractions of a given search space. Due to the number of abstractions, the size of a state changes depending on the level of abstraction used and so I have created a class that outputs a c file describing a given state space after abstraction. The generation of this c file is part of the compilation process and I would like to be able to persist a class which is an extension of this search space. When running the program in the absence of database persistance I simply use the -include $< directive with g++ to make it as if there is a #include directive at the start of my class file, thus making it compile as intended while, not limiting the file to a specific name. My question is whether it is possible to do the same when I use the odb command. As an example my odb command would look like this: odb -d mysql --generate-query --generate-schema person.hxx -include leg.hxx So that I could use it say like odb -d mysal --generate-query --generate-schema person.hxx -include $< where $< is the first dependancy and so is not a fixed file. -- Regards, Teererai Marange Ph: 021521987 From davejohansen at gmail.com Thu Jul 2 15:18:40 2015 From: davejohansen at gmail.com (Dave Johansen) Date: Thu Jul 2 15:18:47 2015 Subject: [odb-users] ODB 2.4 on Fedora and RHEL Message-ID: https://copr.fedoraproject.org/coprs/daveisfera/odb_2.4/ I finally got around to creating a COPR for ODB 2.4 on stable Fedora releases and RHEL. Right now there's no support for RHEL 5 and 6 because they have older versions of gcc, but when I get a chance, I'll create a COPR for those that uses the devtoolset. Also, my hope is to start creating a COPR when new releases are made and hopefully now that I'm familiar with the process, I can create the COPR at the same time that I update Fedora rawhide. Dave From boris at codesynthesis.com Fri Jul 3 13:35:07 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 3 13:35:19 2015 Subject: [odb-users] base class, derived, separate headers and derived references base In-Reply-To: References: Message-ID: MM writes: > dir1/A.hpp > =================== > namespace NS > { > > struct A { > ... > ...const T* underlying; > ... > }; > struct selector { > int id; > int type; > }; > void set_A_underlying(A&, const selector&); > > } > > > dir1_odb/A.hpp > ==================== > #include > namespace NS > { > #pragma db value(selector) definition > > #pragma db object(A) table("A") definition > #pragma db member(A::underlying) transient > #pragma db member(A::ulid) virtual(selector) \ > get( selector(this.underlying->type(), this.underlying->id)) \ > set(set_A_underlying (this,(?))) > } What is a 'T' in A? Send a complete, compilable test case that reproduces the problem. Boris From boris at codesynthesis.com Fri Jul 3 13:47:42 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 3 13:47:56 2015 Subject: [odb-users] Using --generate-schema does not output sql file when using sqlite In-Reply-To: References: Message-ID: Hi Teererai, Teererai Marange writes: > I am working with the hello world example given on the tutorial pages and > am trying to work through all the steps. When I enter > > odb -d sqlite --generate-query --generate-schema person.hxx > > no sql file is generated and so I am not able to create a database > schema on sqlite. How do I proceed in such a situation? By adding the '--schema-format sql' option. Quoting from the ODB command line manual (man page): --generate-schema|-s ... Depending on the database being used (--database option), the schema is generated either as a standalone SQL file or embedded into the generated C++ code. By default the SQL file is generated for the MySQL, PostgreSQL, Oracle, and Microsoft SQL Server databases and the schema is embedded into the C++ code for the SQLite database. Use the --schema-format option to alter the default schema format. ... The reason for generating embedded schema for SQLite is that it is an embedded (as in-process) database and .sql file is seldom used. Boris From boris at codesynthesis.com Fri Jul 3 14:07:29 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 3 14:07:39 2015 Subject: [odb-users] Templated view class In-Reply-To: <1435839354.38887447@apps.rackspace.com> References: <1435839354.38887447@apps.rackspace.com> Message-ID: Hi Dieter, dieter.govaerts@bricsys.com writes: > If I rewrite the view class in a templated form, that is equivalent > in my opinion, as: > > template > struct ObjectNameView > { > String name; > }; > > typedef ObjectNameView CompositionNameView; > #pragma db view(CompositionNameView) object(Composition) > > then the odb compiler succeeds but the (visual) c++ compiler fails: Yes, this is not supported in ODB 2.4.0 but will be in the upcoming release. If you would like, I can build you pre-release packages. Just let me know which platform you need the ODB compiler binary for, if any. Boris From boris at codesynthesis.com Fri Jul 3 14:13:29 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 3 14:13:38 2015 Subject: [odb-users] using the odb command when one of the c files is generated by makefile In-Reply-To: References: Message-ID: Hi Teererai, Teererai Marange writes: > When running the program in the absence of database persistance I simply use > the -include $< directive with g++ to make it as if there is a #include > directive at the start of my class file, thus making it compile as intended > while, not limiting the file to a specific name. My question is whether it > is possible to do the same when I use the odb command. > > As an example my odb command would look like this: > > odb -d mysql --generate-query --generate-schema person.hxx -include leg.hxx ODB has the -x option which instructs it to pass the next argument to g++, verbatim. So it seems to me this should do the trick: odb ... -x -include -x leg.hxx ... Boris From boris at codesynthesis.com Fri Jul 3 14:19:24 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 3 14:19:33 2015 Subject: [odb-users] ODB 2.4 on Fedora and RHEL In-Reply-To: References: Message-ID: Hi Dave, Dave Johansen writes: > https://copr.fedoraproject.org/coprs/daveisfera/odb_2.4/ > > I finally got around to creating a COPR for ODB 2.4 on stable Fedora > releases and RHEL. Right now there's no support for RHEL 5 and 6 because > they have older versions of gcc, but when I get a chance, I'll create a > COPR for those that uses the devtoolset. > Also, my hope is to start creating a COPR when new releases are made and > hopefully now that I'm familiar with the process, I can create the COPR at > the same time that I update Fedora rawhide. Great work, Dave, much appreciated! One note: when following the above link, I see the following in the "Installation Instructions" section: "Instructions not filled in by author. Author knows what to do. Everybody else should avoid this repo." Probably not the message we want to send ;-) Boris From finjulhich at gmail.com Sat Jul 4 20:11:12 2015 From: finjulhich at gmail.com (MM) Date: Sat Jul 4 20:11:20 2015 Subject: [odb-users] base class, derived, separate headers and derived references base In-Reply-To: References: Message-ID: On 3 July 2015 at 18:35, Boris Kolpackov wrote: > MM writes: > NS/Base.hpp ===================== #include #include namespace NS > { struct Base { std::string code; std::uint32_t id; virtual const std::string& type() const =0; virtual ~Base() =0; }; } NS/A.hpp > =================== > namespace NS > { > struct A : public Base { > const Base* underlying; > }; > struct selector { > std::string type; > std::uint32_t id; > }; > void set_A_underlying(A&, const selector&); } NS_odb/A.hpp > ==================== > #include > namespace NS > { > #pragma db value(selector) definition > #pragma db object(A) table("A") definition > #pragma db member(A::underlying) transient > #pragma db member(A::ulid) virtual(selector) \ > get( selector(this.underlying->type(), this.underlying->id)) \ > set(set_A_underlying (this,(?))) > } What is a 'T' in A? Send a complete, compilable test case that > reproduces the problem. > Boris > Please see corrections, for compilable files, above. There's just nothing generated by the odb compiler for the type selector, at all. Rds, MM From davejohansen at gmail.com Sun Jul 5 23:43:20 2015 From: davejohansen at gmail.com (Dave Johansen) Date: Sun Jul 5 23:43:27 2015 Subject: [odb-users] ODB 2.4 on Fedora and RHEL In-Reply-To: References: Message-ID: On Fri, Jul 3, 2015 at 11:19 AM, Boris Kolpackov wrote: > Hi Dave, > > Dave Johansen writes: > > > https://copr.fedoraproject.org/coprs/daveisfera/odb_2.4/ > > > > I finally got around to creating a COPR for ODB 2.4 on stable Fedora > > releases and RHEL. Right now there's no support for RHEL 5 and 6 because > > they have older versions of gcc, but when I get a chance, I'll create a > > COPR for those that uses the devtoolset. > > Also, my hope is to start creating a COPR when new releases are made and > > hopefully now that I'm familiar with the process, I can create the COPR > at > > the same time that I update Fedora rawhide. > > Great work, Dave, much appreciated! > > One note: when following the above link, I see the following in the > "Installation Instructions" section: > > "Instructions not filled in by author. Author knows what to do. > Everybody else should avoid this repo." > > Probably not the message we want to send ;-) Sorry about that. The setup listed those as optional and I didn't realize it listed instructions that sounded so scary. I've fixed it now. From dieter.govaerts at bricsys.com Sat Jul 4 05:33:20 2015 From: dieter.govaerts at bricsys.com (dieter.govaerts@bricsys.com) Date: Mon Jul 6 12:13:15 2015 Subject: [odb-users] Query a many-to-many relationship Message-ID: <1436002400.551919736@apps.rackspace.com> Hallo, I've been though all example projects (2.3.0) but I don't seem to find an easy way to query objects based on a many-to-many relationship. Referring to the 'relationship' example project, how can I query all employees working on project "Complex Hardware"? Thanks, Dieter From selection989 at gmail.com Mon Jul 6 05:46:17 2015 From: selection989 at gmail.com (Teererai Marange) Date: Mon Jul 6 12:13:15 2015 Subject: [odb-users] Persisting class for which part of the code is generated at compile time. Message-ID: I have a project that consists of the following files: Node.h Node.cpp resultSet.h resultSet.cpp bfs.h bfs.cpp 8puzzle.c The goal of this project is to run breadth first search and the persist the results to a database. To do this, I have created made the objects described by resultSet.h and Node.h persistant. Worth noting is the fact that some of the objects that describe a Node are generated and stored in 8puzzle.c at runtime. For this reason, in order to make resultSet persistant I used: odb -d mysql --generate-query --generate-schema --std c++11 resultSet.h -x -include -x 8puzzle.c and odb -d mysql --generate-query --generate-schema --std c++11 Node.h -x -include -x 8puzzle.c I then tried to compile Node-odb.cxx using: g++ -c Node-odb.cxx -include 8puzzle.c and the following error was returned: Node-odb.cxx: In static member function ?static bool odb::access::object_traits_impl::init(odb::access::object_traits_impl::image_type&, const object_type&, odb::mysql::statement_kind)?: Node-odb.cxx:233:10: error: no matching function for call to ?odb::mysql::value_traits::set_image(odb::details::buffer&, std::size_t&, bool&, const state_t&)? v); ^ Node-odb.cxx:233:10: note: candidate is: In file included from /usr/local/include/odb/mysql/query.hxx:20:0, from Node-odb.hxx:86, from Node-odb.cxx:7: /usr/local/include/odb/mysql/traits.hxx:323:7: note: static void odb::mysql::default_value_traits >::set_image(odb::mysql::default_value_traits >::image_type&, bool&, T) [with T = state_t; odb::mysql::database_type_id ID = (odb::mysql::database_type_id)16u; odb::mysql::default_value_traits >::image_type = odb::details::basic_buffer] set_image (image_type& i, bool& is_null, T v) ^ /usr/local/include/odb/mysql/traits.hxx:323:7: note: candidate expects 3 arguments, 4 provided Node-odb.cxx: In static member function ?static void odb::access::object_traits_impl::init(odb::access::object_traits::object_type&, const odb::access::object_traits_impl::image_type&, odb::database*)?: Node-odb.cxx:330:26: error: no matching function for call to ?odb::mysql::value_traits::set_value(state_t&, const buffer&, const long unsigned int&, const my_bool&)? i.base_state_null); ^ Node-odb.cxx:330:26: note: candidate is: In file included from /usr/local/include/odb/mysql/query.hxx:20:0, from Node-odb.hxx:86, from Node-odb.cxx:7: /usr/local/include/odb/mysql/traits.hxx:314:7: note: static void odb::mysql::default_value_traits >::set_value(T&, const image_type&, bool) [with T = state_t; odb::mysql::database_type_id ID = (odb::mysql::database_type_id)16u; odb::mysql::default_value_traits >::image_type = odb::details::basic_buffer] set_value (T& v, const image_type& i, bool is_null) ^ /usr/local/include/odb/mysql/traits.hxx:314:7: note: candidate expects 3 arguments, 4 provided /usr/local/include/odb/mysql/traits.hxx: In instantiation of ?static void odb::mysql::default_value_traits >::set_image(odb::mysql::default_value_traits >::image_type&, bool&, T) [with T = state_t; odb::mysql::database_type_id ID = (odb::mysql::database_type_id)16u; odb::mysql::default_value_traits >::image_type = odb::details::basic_buffer]?: Node-odb.cxx:229:31: required from here /usr/local/include/odb/mysql/traits.hxx:326:11: error: no matching function for call to ?odb::details::basic_buffer::basic_buffer(state_t&)? i = image_type (v); ^ /usr/local/include/odb/mysql/traits.hxx:326:11: note: candidates are: In file included from Node-odb.hxx:80:0, from Node-odb.cxx:7: /usr/local/include/odb/details/buffer.hxx:52:7: note: odb::details::basic_buffer::basic_buffer(std::size_t) [with T = char; std::size_t = long unsigned int] basic_buffer (std::size_t capacity = 256) ^ /usr/local/include/odb/details/buffer.hxx:52:7: note: no known conversion for argument 1 from ?state_t? to ?std::size_t {aka long unsigned int}? /usr/local/include/odb/details/buffer.hxx:49:11: note: odb::details::basic_buffer::basic_buffer(const odb::details::basic_buffer&) class basic_buffer: public basic_buffer_base ^ /usr/local/include/odb/details/buffer.hxx:49:11: note: no known conversion for argument 1 from ?state_t? to ?const odb::details::basic_buffer&? In file included from /usr/local/include/odb/mysql/query.hxx:20:0, from Node-odb.hxx:86, from Node-odb.cxx:7: /usr/local/include/odb/mysql/traits.hxx: In instantiation of ?static void odb::mysql::default_value_traits >::set_value(T&, const image_type&, bool) [with T = state_t; odb::mysql::database_type_id ID = (odb::mysql::database_type_id)16u; odb::mysql::default_value_traits >::image_type = odb::details::basic_buffer]?: Node-odb.cxx:326:31: required from here /usr/local/include/odb/mysql/traits.hxx:317:13: error: no matching function for call to ?state_t::state_t(const image_type&)? v = T (i); ^ /usr/local/include/odb/mysql/traits.hxx:317:13: note: candidates are: In file included from :0:0: ./8puzzle.c:35:3: note: state_t::state_t() } state_t; ^ ./8puzzle.c:35:3: note: candidate expects 0 arguments, 1 provided ./8puzzle.c:35:3: note: state_t::state_t(const state_t&) ./8puzzle.c:35:3: note: no known conversion for argument 1 from ?const image_type {aka const odb::details::basic_buffer}? to ?const state_t&? baring in mind that the code describing state_t is located in 8puzzle.c is there anyway around this and what exactly is the problem? Regards, Teererai Marange Ph: 021521987 From boris at codesynthesis.com Mon Jul 6 12:23:05 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 6 12:23:14 2015 Subject: [odb-users] base class, derived, separate headers and derived references base In-Reply-To: References: Message-ID: MM writes: > Please see corrections, for compilable files, above. Recreated your structure, then: odb -d sqlite NS_odb/A.hpp NS_odb/A.hpp:6:26: error: unable to resolve type name 'selector' in db pragma value NS_odb/A.hpp:8:20: error: unable to resolve type name 'A' in db pragma object NS_odb/A.hpp:10:19: error: unable to resolve type name 'A' in db pragma member NS_odb/A.hpp:12:19: error: unable to resolve type name 'A' in db pragma member Want to try again to send a *complete*, *compilable* test case? Or going to waste more time? Boris From boris at codesynthesis.com Mon Jul 6 12:37:59 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 6 12:38:09 2015 Subject: [odb-users] Query a many-to-many relationship In-Reply-To: <1436002400.551919736@apps.rackspace.com> References: <1436002400.551919736@apps.rackspace.com> Message-ID: Hi Dieter, dieter.govaerts@bricsys.com writes: > I've been though all example projects (2.3.0) but I don't seem to find > an easy way to query objects based on a many-to-many relationship. > > Referring to the 'relationship' example project, how can I query all > employees working on project "Complex Hardware"? That is actually not a to-many relationship, so you can use normal object queries: typedef odb::query query; db.query (query::employer->name == "Complex Hardware"); For real to-many relationships you would use a view. If you want to load the whole object, then you would use an object loading view (Section 10.2 in the ODB manual; available since 2.4.0). Boris From boris at codesynthesis.com Mon Jul 6 12:47:44 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 6 12:47:53 2015 Subject: [odb-users] Persisting class for which part of the code is generated at compile time. In-Reply-To: References: Message-ID: Hi Teererai, Teererai Marange writes: > odb -d mysql --generate-query --generate-schema --std c++11 resultSet.h > -x -include -x 8puzzle.c > > [...] > > baring in mind that the code describing state_t is located in 8puzzle.c is > there anyway around this and what exactly is the problem? The normal ODB compilation works this way: the ODB compiler generates a set of -odb files that include your header file (resultSet.h). In your case, resultSet.h is incomplete since it needs that 8puzzle.c "prefix". So my guess is that because this prefix is not included into the generated header, things break. Some things I would suggest you consider using: - Various --*-prologue/epilogue options to include 8puzzle.c at the appropriate place in the generated code. - --odb-prologue instead of -include to include 8puzzle.c in the ODB compilation (probably a cleaner way, forgot to mention it in my earlier reply). - The 'definition' pragma to tell the ODB compiler which file it should treat as the "definition" of a class. Boris From David.Sarrut at creatis.insa-lyon.fr Tue Jul 7 04:36:38 2015 From: David.Sarrut at creatis.insa-lyon.fr (David Sarrut) Date: Tue Jul 7 04:37:05 2015 Subject: [odb-users] on_delete Message-ID: Hello, I use a persistent table, say "MyFile", that store filename of a file stored on disk. When I delete a MyFile record, I should be able to delete the file on disk. Is a on_delete(myfunction) available in odb ? If not, how can I implement this thing ? thanks, David -- David Sarrut, Phd Directeur de recherche CNRS CREATIS, UMR CNRS 5220, Inserm U 1044 Centre de lutte contre le cancer L?on B?rard 28 rue La?nnec, 69373 Lyon cedex 08 Tel : 04 78 78 51 51 / 06 74 72 05 42 http://www.creatis.insa-lyon.fr/~dsarrut _________________________________ "2 + 2 = 5, for extremely large values of 2" _________________________________ From dieter.govaerts at bricsys.com Mon Jul 6 15:09:16 2015 From: dieter.govaerts at bricsys.com (dieter.govaerts@bricsys.com) Date: Tue Jul 7 11:08:54 2015 Subject: [odb-users] Query a many-to-many relationship In-Reply-To: References: <1436002400.551919736@apps.rackspace.com> Message-ID: <1436209756.2819530@apps.rackspace.com> Hello Boris, On Monday, 6 July, 2015 18:37, "Boris Kolpackov" said: > dieter.govaerts@bricsys.com writes: > >> I've been though all example projects (2.3.0) but I don't seem to find >> an easy way to query objects based on a many-to-many relationship. >> >> Referring to the 'relationship' example project, how can I query all >> employees working on project "Complex Hardware"? > > That is actually not a to-many relationship, so you can use normal > object queries: > > typedef odb::query query; > > db.query (query::employer->name == "Complex Hardware"); > > For real to-many relationships you would use a view. If you want > to load the whole object, then you would use an object loading view > (Section 10.2 in the ODB manual; available since 2.4.0). I wanted to query employees based on the name of the _projects_ they work on, not its employers name. Object loading views seems indeed the key. I'll have to upgrade to 2.4.0 and try again. Thank you. Dieter From boris at codesynthesis.com Tue Jul 7 11:13:48 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Jul 7 11:13:57 2015 Subject: [odb-users] Query a many-to-many relationship In-Reply-To: <1436209756.2819530@apps.rackspace.com> References: <1436002400.551919736@apps.rackspace.com> <1436209756.2819530@apps.rackspace.com> Message-ID: Hi Dieter, dieter.govaerts@bricsys.com writes: > I wanted to query employees based on the name of the _projects_ they > work on, not its employers name. Yes, you are right. Sorry, it was a long day. Here is an object loading view example that should do the trick: #pragma db view object(employee) object(project) struct employee_projects { std::shared_ptr e; }; typedef odb::query query; db.query (query::project::name == "Complex Hardware"); Boris From boris at codesynthesis.com Tue Jul 7 11:17:24 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Jul 7 11:17:33 2015 Subject: [odb-users] on_delete In-Reply-To: References: Message-ID: Hi David, David Sarrut writes: > I use a persistent table, say "MyFile", that store filename of a file > stored on disk. When I delete a MyFile record, I should be able to delete > the file on disk. Is a on_delete(myfunction) available in odb ? If not, > how can I implement this thing ? Perhaps what you are looking for is database operation callbacks (Section 14.1.7 in the ODB manual), specifically, the post_erase event? Boris From David.Sarrut at creatis.insa-lyon.fr Wed Jul 8 01:25:46 2015 From: David.Sarrut at creatis.insa-lyon.fr (David Sarrut) Date: Wed Jul 8 01:26:14 2015 Subject: [odb-users] on_delete In-Reply-To: References: Message-ID: exact yes ! Sorry, I missed that in the doc, thank you ! David On Tue, Jul 7, 2015 at 5:17 PM, Boris Kolpackov wrote: > Hi David, > > David Sarrut writes: > > > I use a persistent table, say "MyFile", that store filename of a file > > stored on disk. When I delete a MyFile record, I should be able to delete > > the file on disk. Is a on_delete(myfunction) available in odb ? If not, > > how can I implement this thing ? > > Perhaps what you are looking for is database operation callbacks (Section > 14.1.7 in the ODB manual), specifically, the post_erase event? > > Boris > -- David Sarrut, Phd Directeur de recherche CNRS CREATIS, UMR CNRS 5220, Inserm U 1044 Centre de lutte contre le cancer L?on B?rard 28 rue La?nnec, 69373 Lyon cedex 08 Tel : 04 78 78 51 51 / 06 74 72 05 42 http://www.creatis.insa-lyon.fr/~dsarrut _________________________________ "2 + 2 = 5, for extremely large values of 2" _________________________________ From David.Sarrut at creatis.insa-lyon.fr Wed Jul 8 02:59:49 2015 From: David.Sarrut at creatis.insa-lyon.fr (David Sarrut) Date: Wed Jul 8 03:00:17 2015 Subject: [odb-users] on_delete In-Reply-To: References: Message-ID: Hello again, it seems that when ondelete(cascade) pragma is used, the callback are not called for the "ondeleted" record, am I right ? David On Wed, Jul 8, 2015 at 7:25 AM, David Sarrut < David.Sarrut@creatis.insa-lyon.fr> wrote: > > exact yes ! Sorry, I missed that in the doc, thank you ! > > David > > On Tue, Jul 7, 2015 at 5:17 PM, Boris Kolpackov > wrote: > >> Hi David, >> >> David Sarrut writes: >> >> > I use a persistent table, say "MyFile", that store filename of a file >> > stored on disk. When I delete a MyFile record, I should be able to >> delete >> > the file on disk. Is a on_delete(myfunction) available in odb ? If not, >> > how can I implement this thing ? >> >> Perhaps what you are looking for is database operation callbacks (Section >> 14.1.7 in the ODB manual), specifically, the post_erase event? >> >> Boris >> > > > > -- > David Sarrut, Phd > Directeur de recherche CNRS > CREATIS, UMR CNRS 5220, Inserm U 1044 > Centre de lutte contre le cancer L?on B?rard > 28 rue La?nnec, 69373 Lyon cedex 08 > Tel : 04 78 78 51 51 / 06 74 72 05 42 > http://www.creatis.insa-lyon.fr/~dsarrut > _________________________________ > "2 + 2 = 5, for extremely large values of 2" > _________________________________ > -- David Sarrut, Phd Directeur de recherche CNRS CREATIS, UMR CNRS 5220, Inserm U 1044 Centre de lutte contre le cancer L?on B?rard 28 rue La?nnec, 69373 Lyon cedex 08 Tel : 04 78 78 51 51 / 06 74 72 05 42 http://www.creatis.insa-lyon.fr/~dsarrut _________________________________ "2 + 2 = 5, for extremely large values of 2" _________________________________ From boris at codesynthesis.com Wed Jul 8 12:08:58 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 8 12:09:07 2015 Subject: [odb-users] on_delete In-Reply-To: References: Message-ID: Hi David, David Sarrut writes: > it seems that when ondelete(cascade) pragma is used, the callback are not > called for the "ondeleted" record, am I right ? Yes, you are correct. ODB may be good, but it is not magic. In fact, in the documentation of on_delete (Section 14.4.15) there is a warning exactly to this effect. It starts like this:" "Note that this is a database-level functionality and care must be taken in order not to end up with inconsistent object states in the application's memory and database. [...]" Boris From david.sarrut at gmail.com Thu Jul 9 01:54:41 2015 From: david.sarrut at gmail.com (David Sarrut) Date: Thu Jul 9 10:55:08 2015 Subject: [odb-users] on_delete In-Reply-To: References: Message-ID: I would had liked a little bit of magic;) Anyway I will find another way, thank, David > Le 8 juil. 2015 ? 18:08, Boris Kolpackov a ?crit : > > Hi David, > > David Sarrut writes: > >> it seems that when ondelete(cascade) pragma is used, the callback are not >> called for the "ondeleted" record, am I right ? > > Yes, you are correct. ODB may be good, but it is not magic. > > In fact, in the documentation of on_delete (Section 14.4.15) > there is a warning exactly to this effect. It starts like > this:" > > "Note that this is a database-level functionality and care > must be taken in order not to end up with inconsistent object > states in the application's memory and database. [...]" > > Boris From gratta at visuol.com Thu Jul 9 10:25:02 2015 From: gratta at visuol.com (Florent GRATTA) Date: Thu Jul 9 10:55:08 2015 Subject: [odb-users] Query to many relation Message-ID: <98d031a9a58db39a5b7c489f716d227d@visuol.com> Hi, I have the following data model #pragma db object class UserProfile { public: UserProfile() { } const std::string& getEmail() const { return m_email; } void setEmail(const std::string& email) { m_email = email; } const std::string& getFirstName() const { return m_firstName; } void setFirstName(const std::string& firstName) { m_firstName = firstName; } const std::string& getLastName() const { return m_lastName; } void setLastName(const std::string& lastName) { m_lastName = lastName; } const std::string& getPassword() const { return m_password; } void setPassword(const std::string& password) { m_password = password; } const std::string& getLogin() const { return m_login; } void setLogin(const std::string& login) { m_login = login; } private: #pragma db id std::string m_login; std::string m_password; std::string m_firstName; std::string m_lastName; std::string m_email; }; --------------------------------------------------------------- #pragma db object class UserGroup { public: UserGroup() { } const std::string& getName() const { return m_name; } void setName(const std::string& name) { m_name = name; } const std::vector >& getUserprofiles() const { return m_userprofiles; } void setUserprofiles( const std::vector >& userprofiles) { m_userprofiles = userprofiles; } private: #pragma db id std::string m_name; #pragma db value_not_null unordered std::vector> m_userprofiles; }; --------------------------------------------------------------- I would like to return a list of UserGroup associated to the UserProfile. But compiler tolds me that: error: 'm_userprofiles' is not a member of 'query {aka odb::query}' at line result r (m_db->query (query::m_userprofiles->login == login)); My code : typedef odb::query query; typedef odb::result result; std::shared_ptr> listUserGroups (new std::list()); try { transaction t (m_db->begin ()); result r (m_db->query (query::m_userprofiles->login == login)); for (result::iterator i (r.begin ()); i != r.end (); ++i) { listUserGroups ->push_back(*i); } t.commit (); } catch (const odb::exception& e) { std::wcout << e.what () << std::endl; //return nullptr; } return listUserGroups ; From boris at codesynthesis.com Thu Jul 9 11:03:05 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Jul 9 11:03:12 2015 Subject: [odb-users] Query to many relation In-Reply-To: <98d031a9a58db39a5b7c489f716d227d@visuol.com> References: <98d031a9a58db39a5b7c489f716d227d@visuol.com> Message-ID: Hi Florent, Florent GRATTA writes: > I would like to return a list of UserGroup associated to the > UserProfile. [...] The same question was asked just two days ago: http://www.codesynthesis.com/pipermail/odb-users/2015-July/002665.html http://www.codesynthesis.com/pipermail/odb-users/2015-July/002668.html http://www.codesynthesis.com/pipermail/odb-users/2015-July/002672.html Boris From finjulhich at gmail.com Sat Jul 11 06:48:01 2015 From: finjulhich at gmail.com (MM) Date: Sat Jul 11 06:48:10 2015 Subject: [odb-users] base class, derived, separate headers and derived references base In-Reply-To: References: Message-ID: On 6 July 2015 at 17:23, Boris Kolpackov wrote: > MM writes: > > > Please see corrections, for compilable files, above. > > Recreated your structure, then: > > odb -d sqlite NS_odb/A.hpp > > NS_odb/A.hpp:6:26: error: unable to resolve type name 'selector' in db > pragma value > NS_odb/A.hpp:8:20: error: unable to resolve type name 'A' in db pragma > object > NS_odb/A.hpp:10:19: error: unable to resolve type name 'A' in db pragma > member > NS_odb/A.hpp:12:19: error: unable to resolve type name 'A' in db pragma > member > > Want to try again to send a *complete*, *compilable* test case? Or > going to waste more time? > > Boris > This was missing a include. I have attached a tgz of the 3 source headers and the generated odb .?xx files, generated with: odb -d sqlite --std c++11 -I. NS_odb/A.hpp Once the hxx included in my main source, I believe the error would be: A-odb.hxx: 76: composite_value_traits< ::NS::selector, id_sqlite >::image_type ulid_value image_type does not name a type Looking at the the hxx, it just appears to me now the composite_value_traits< ::NS::selector, id_sqlite > class is defined _after_ this point (line 76). Is that why I have this error? Is there a way to force generation of that class for selector before? -------------- next part -------------- A non-text attachment was scrubbed... Name: basederived.tgz Type: application/x-gzip Size: 2336 bytes Desc: not available Url : http://codesynthesis.com/pipermail/odb-users/attachments/20150711/54e33481/basederived.bin From andrey.psv at gmail.com Tue Jul 14 06:29:46 2015 From: andrey.psv at gmail.com (Andrey Paraskevopulo) Date: Tue Jul 14 07:02:10 2015 Subject: [odb-users] Changing global locale may lead to database connection error. PostgreSQL Message-ID: version: libodb-pgsql-2.4.0 Changing global locale may lead to database connection error. Example: int _tmain( int argc, _TCHAR* argv[] ) { std::locale current_locale("");//users locale is Russian_Russia.1251 std::locale::global(current_locale);//change global locale ... odb::pgsql::database db("user", "password", ""/*db*/, "localhost", 5432); auto conn = db_db->connection(); } throws an exception: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5 432? ... !!! port value is 5 432 (thousands is separated by the ? ?, the same port value is used for PQconnectdb(const char *conninfo)) Explanation: odb::pgsql::database has the conninfo_(std::string) member. conninfo_ is initialized with strings with connection parameters. String is created by the ostringstream. One of the parameter is the port (unsigned int). Convertion from the int to string depends on the current global locale (every new stream is imbued with a copy of it). Initially, the global locale is the standard C locale. But if the global locale is changed, than the string port value may be formatted as not expected. Possible solution: libodb-pgsql-2.4.0 For each ostringstream set a stream a default C locale to produce current locale-independent text. ostringstream ss; imbue(std::locale::classic()); ? Andrey Paraskevopulo From modriscoll at clearpathrobotics.com Thu Jul 16 18:39:54 2015 From: modriscoll at clearpathrobotics.com (Mike O'Driscoll) Date: Thu Jul 16 18:40:21 2015 Subject: [odb-users] Crash on accessing odb::result object. Message-ID: Hello Users, I'm in the process of evaluating the ODB libraries using Postgresql and encountering the following crash after getting results from a query. If I only instantiate "r" and don't provide it a query result everything works fine. Although if I call "db_->query" and act upon the results, I get a segfault on empty or trying to work with the iterator. I've tried to follow the examples as closely as possible but continue to be unable to progress. Any thoughts or insights would be appriciated. GDB backtrace: Program received signal SIGSEGV, Segmentation fault. #0 0x00007ffff416a4a0 in odb::pgsql::select_statement::next() () > from /usr/lib/x86_64-linux-gnu/libodb-pgsql-2.4.so > #1 0x00007ffff6bb9edc in > odb::pgsql::object_result_impl::next (this=0x65cb10) at > /usr/include/odb/pgsql/simple-object-result.txx:102 > #2 0x00007ffff6bb291a in begin (this=0x65cb10) > at /usr/include/odb/simple-object-result.hxx:76 > #3 empty (this=0x7fffffffc720) at /usr/include/odb/result.hxx:200 > #4 mytype::orm::MyORM::getUncompletedTasks (this=0x64f610) > at /path/to/my_orm.cpp:107 Code: odb::core::transaction t(db_->begin()); > odb::core::query q_rt; > q_rt = odb::core::query( > odb::core::query::task_state > != mytype::orm::COMPLETED); > ROS_INFO("ORM: Querying for uncompleted tasks"); > // Transact the database and query it. > odb::core::result r = > db_->query(q_rt); > t.commit(); > ROS_INFO("ORM: Processing results, count: %d", r.size()); > // Take all results and push them to a results vector > if (!r.empty()) > { > for (odb::result::iterator i = r.begin(); > i != r.end(); > ++i) > { > ROS_INFO("ORM: Processing Loop"); > // non_complete_tasks.push_back(i->task()); > } > } > ROS_INFO("ORM: Found %d, uncompleted tasks", non_complete_tasks.size()); -- Mike O'Driscoll From fasdfasdas at gmail.com Thu Jul 16 20:46:08 2015 From: fasdfasdas at gmail.com (=?UTF-8?B?VG9sZ2EgSE/FnkfDllI=?=) Date: Thu Jul 16 20:46:25 2015 Subject: [odb-users] Crash on accessing odb::result object. In-Reply-To: References: Message-ID: You cannot operate on result (iterating in this code) after ending the transaction. On Fri, Jul 17, 2015 at 1:40 AM Mike O'Driscoll < modriscoll@clearpathrobotics.com> wrote: > Hello Users, > > I'm in the process of evaluating the ODB libraries using Postgresql and > encountering the following crash after getting results from a query. > > If I only instantiate "r" and don't provide it a query result everything > works fine. > Although if I call "db_->query" and act upon the results, I get a segfault > on empty or trying to work with the iterator. > > I've tried to follow the examples as closely as possible but continue to be > unable to progress. > Any thoughts or insights would be appriciated. > > GDB backtrace: > > Program received signal SIGSEGV, Segmentation fault. > > #0 0x00007ffff416a4a0 in odb::pgsql::select_statement::next() () > > from /usr/lib/x86_64-linux-gnu/libodb-pgsql-2.4.so > > #1 0x00007ffff6bb9edc in > > odb::pgsql::object_result_impl::next (this=0x65cb10) > at > > /usr/include/odb/pgsql/simple-object-result.txx:102 > > #2 0x00007ffff6bb291a in begin (this=0x65cb10) > > at /usr/include/odb/simple-object-result.hxx:76 > > #3 empty (this=0x7fffffffc720) at /usr/include/odb/result.hxx:200 > > #4 mytype::orm::MyORM::getUncompletedTasks (this=0x64f610) > > at /path/to/my_orm.cpp:107 > > > > Code: > > odb::core::transaction t(db_->begin()); > > odb::core::query q_rt; > > q_rt = odb::core::query( > > odb::core::query::task_state > > != mytype::orm::COMPLETED); > > ROS_INFO("ORM: Querying for uncompleted tasks"); > > // Transact the database and query it. > > odb::core::result r = > > db_->query(q_rt); > > t.commit(); > > ROS_INFO("ORM: Processing results, count: %d", r.size()); > > // Take all results and push them to a results vector > > if (!r.empty()) > > { > > for (odb::result::iterator i = r.begin(); > > i != r.end(); > > ++i) > > { > > ROS_INFO("ORM: Processing Loop"); > > // non_complete_tasks.push_back(i->task()); > > } > > } > > ROS_INFO("ORM: Found %d, uncompleted tasks", > non_complete_tasks.size()); > > > > -- > Mike O'Driscoll > From boris at codesynthesis.com Fri Jul 17 05:59:37 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 17 05:59:43 2015 Subject: [odb-users] Crash on accessing odb::result object. In-Reply-To: References: Message-ID: Hi Mike, Tolga HO?G?R writes: > You cannot operate on result (iterating in this code) after ending the > transaction. Yes, Tolga is correct. To expand on this, query result is like a stream and the database keeps sending the data (rows) as we iterate over it. And this can clearly only be done while in transaction. Once the transaction is committed or rolled back, all results that were created as part of it are invalidated. Boris From boris at codesynthesis.com Fri Jul 17 06:52:57 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 17 06:53:04 2015 Subject: [odb-users] base class, derived, separate headers and derived references base In-Reply-To: References: Message-ID: Hi, MM writes: > Looking at the the hxx, it just appears to me now the > composite_value_traits< ::NS::selector, id_sqlite > class is defined > _after_ this point (line 76). Is that why I have this error? Thanks for the test. Yes, this is the source of the problem. Composite values should be defined before being used. This normally gets enforced naturally (because you cannot use a type in a data member until it is defined), but in case of virtual data members, this can be subverted. I've added a check for this to the ODB compiler. Now, for your case, it prints: NS/A.hpp:6:8: error: composite value type ::NS::selector must be defined before being used in class ::NS::A NS_odb/A.hpp:10:12: info: data member ulid uses selector NS/A.hpp:10:8: info: class selector is define here > Is there a way to force generation of that class for selector before? No, if the two entities (object A and selector, in your case) are generated into the same source file, then they are generated in the order they are defined in C++. So the two ways to fix your example are: (1) move selector before A in A.hpp or (2) generate A and selector into different source files. I've done (1) and after fixing a couple of other bugs in your example, the generated code compiles fine. Boris From boris at codesynthesis.com Fri Jul 17 07:19:58 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 17 07:20:04 2015 Subject: [odb-users] Changing global locale may lead to database connection error. PostgreSQL In-Reply-To: References: Message-ID: Hi Andrey, Thanks for the detailed bug report, much appreciated. This locale business is quite a can of warms. Here are some thoughs/notes: 1. Based on my experience, changing global locale to anything other than "C" is a sure way to end up in all kinds of trouble. See this email for some more information: http://codesynthesis.com/pipermail/xsd-users/2015-February/004526.html 2. Because of (1), I believe this is very seldom done and creating and setting "C" locale in every case where we use stringstream will be a performance drag that is unnecessary in 99.9% cases. 3. The proper way to fix this is to use C++11 to_string() and sto*() functions, which always use "C" locale. I've added an item to our TODO list to do just that once we drop C++98 support (hint: yes, it is coming, and soon ;-)). Boris From modriscoll at clearpathrobotics.com Fri Jul 17 09:34:15 2015 From: modriscoll at clearpathrobotics.com (Mike O'Driscoll) Date: Fri Jul 17 09:34:41 2015 Subject: [odb-users] Crash on accessing odb::result object. In-Reply-To: References: Message-ID: Thanks for the quick response Tolga, this immediately solved the issue. And than you Boris for the technical reasoning, this help me understand the underlying functionality so to not make similar mistaks. Cheers, -- Mike O'Driscoll On Fri, Jul 17, 2015 at 5:59 AM, Boris Kolpackov wrote: > Hi Mike, > > Tolga HO?G?R writes: > > > You cannot operate on result (iterating in this code) after ending the > > transaction. > > Yes, Tolga is correct. To expand on this, query result is like > a stream and the database keeps sending the data (rows) as we > iterate over it. And this can clearly only be done while in > transaction. Once the transaction is committed or rolled back, > all results that were created as part of it are invalidated. > > Boris > From finjulhich at gmail.com Sun Jul 19 04:51:02 2015 From: finjulhich at gmail.com (MM) Date: Sun Jul 19 04:51:11 2015 Subject: [odb-users] base class, derived, separate headers and derived references base In-Reply-To: References: Message-ID: yes I had done that... Thanks for adding the error in the odb compiler. On 17 July 2015 at 11:52, Boris Kolpackov wrote: > Hi, > > MM writes: > > > Looking at the the hxx, it just appears to me now the > > composite_value_traits< ::NS::selector, id_sqlite > class is defined > > _after_ this point (line 76). Is that why I have this error? > > Thanks for the test. Yes, this is the source of the problem. Composite > values should be defined before being used. This normally gets enforced > naturally (because you cannot use a type in a data member until it is > defined), but in case of virtual data members, this can be subverted. > > I've added a check for this to the ODB compiler. Now, for your case, > it prints: > > NS/A.hpp:6:8: error: composite value type ::NS::selector must be defined > before being used in class ::NS::A > NS_odb/A.hpp:10:12: info: data member ulid uses selector > NS/A.hpp:10:8: info: class selector is define here > > > > Is there a way to force generation of that class for selector before? > > No, if the two entities (object A and selector, in your case) are > generated into the same source file, then they are generated in > the order they are defined in C++. So the two ways to fix your > example are: (1) move selector before A in A.hpp or (2) generate > A and selector into different source files. > > I've done (1) and after fixing a couple of other bugs in your > example, the generated code compiles fine. > > Boris > From mne at qosmotec.com Mon Jul 20 12:39:18 2015 From: mne at qosmotec.com (Marcel Nehring) Date: Mon Jul 20 12:40:57 2015 Subject: [odb-users] Name clash when using nested value types with pointer Message-ID: <37edc0a951304a1b93788cca580374ac@QEX.qosmotec.com> Hi Boris, I discovered an issue with the ODB compiler today. A short, self-contained, compilable, example is attached below. When nesting value objects where one of the inner objects has a pointer to some other object, the ODB compiler creates nested structs and names these structs according to the names of the corresponding member variables. If the names happen to be identical this leads to a compile error. In case you find time to fix the problem it would be nice if you could again provide a pre-release binary package including the fix. Thanks & best regards, Marcel #include #pragma db object class Object { public: #pragma db id int id; }; #pragma db value class Value { public: std::shared_ptr m_object; }; #pragma db value class Bar { public: Value m_value; }; #pragma db object class Foo { public: Bar m_value; #pragma db id int id; }; From marcos.glez at gmail.com Sat Jul 18 03:59:57 2015 From: marcos.glez at gmail.com (Marcos Gonzalez Menendez) Date: Mon Jul 20 13:07:14 2015 Subject: [odb-users] qt5 solution for VS2013 Message-ID: I'm writing just to mention that the solution file libodb-qt5-vc12.sln has a reference to the vc11 project. I've changed locally this reference and everything went ok since the generated files contain the vc12 suffix (odb-qt5-2.4-vc12.dll, etc.) Thanks to all the codesynthesis team for this wonderful library -- Marcos Gonz?lez Men?ndez From hicham at mouline.org Sun Jul 19 04:55:47 2015 From: hicham at mouline.org (Hicham Mouline) Date: Mon Jul 20 13:07:14 2015 Subject: [odb-users] get() and c++11 aggregate initialization Message-ID: Hi, With c++11, in a odb pragma, I have an explicit accessor. struct selector { int a; int b; }; If I have a virtual member of type selector, can I use brace-initialization to return an object of that type, like #pragma ......... get( selector{ 1, 5 } ) From boris at codesynthesis.com Mon Jul 20 13:21:54 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 20 13:21:57 2015 Subject: [odb-users] get() and c++11 aggregate initialization In-Reply-To: References: Message-ID: Hi Hicham, Hicham Mouline writes: > If I have a virtual member of type selector, can I use brace-initialization > to return an object of that type, like > > #pragma ......... get( selector{ 1, 5 } ) You should be, except that there is a bug in the (released) ODB compiler that would prevent you from using this feature. It has been fixed for the upcoming release, if you would like to try the patch: http://scm.codesynthesis.com/?p=odb/odb.git;a=commit;h=4d134880196e85e06d5ff4e83a26a3b15027706a Boris From boris at codesynthesis.com Mon Jul 20 13:27:42 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 20 13:27:45 2015 Subject: [odb-users] qt5 solution for VS2013 In-Reply-To: References: Message-ID: Hi Marcos, Marcos Gonzalez Menendez writes: > I'm writing just to mention that the solution file libodb-qt5-vc12.sln has > a reference to the vc11 project. Fixed, thanks for the report! > Thanks to all the codesynthesis team for this wonderful library Thanks, I am glad you are enjoying it. Boris From finjulhich at gmail.com Mon Jul 20 14:32:50 2015 From: finjulhich at gmail.com (MM) Date: Mon Jul 20 14:32:57 2015 Subject: [odb-users] polymorphic inheritance, typeid, odb::object_not_persistent Message-ID: Hello, I have the following: namespace NS { class Base { public: const std::string& name() const; void name(const std::string&); virtual ~exchange() =default; protected: exchange() = default; exchange(const std::string&, const sometype&); private: std::string name_; const sometype* cal_; }; class D1 : public Base { public: D1() = default; D1(const std::string&,const sometype&); private: /// some virtual function overrides }; class D2 : public Base { /// same }; ... class D10 : public Base { /// same }; } The SQL that was just generated by the odb compiler is: CREATE TABLE "Base" ( "name" TEXT NULL PRIMARY KEY, "typeid" TEXT NULL, "cal" TEXT NULL, CONSTRAINT "cal_fk" FOREIGN KEY ("cal") REFERENCES "OtherTable" ("name") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE "D1" ( "name" TEXT NULL PRIMARY KEY, CONSTRAINT "name_fk" FOREIGN KEY ("name") REFERENCES "Base" ("name") ON DELETE CASCADE); /// and so on for all the D2... D10 In the database, table Base looks like: name typeid cal D1 NS::D1 NULL D2 NS::D2 cal2 ... D10 NS::D10 NULL and there is 1 table for each of the derived classes, each with 1 row and 1 column: table D1: name D1 table D2: name D2 ... and so on. When running this loading code odb::sqlite::database db{settings.db_filename, SQLITE_OPEN_READONLY}; odb::session s; odb::transaction t{ db.begin() }; { auto res = db.query(); std::size_t cnt = 0u; for (auto i=std::begin(res); i!=std::end(res); ++i, ++cnt) some_function( i.load() ); std::cout<<" "< References: Message-ID: Hi, MM writes: > I get this exception: odb::object_not_persistent > > The intent is to load from the database all the persistent objects (the > derived) from the Base table, and assign them a concrete derived instance > (D1...D10) according to the typeid, and populate the name field > > I don't know if this is expected to work, and what is the correction if > something is wrong. Yes, the polymorpism part is expected to work, and from what you have shown (i.e., no database mapping pragmas -- always a good idea to include), I don't see anything wrong. Perhaps it is that 'cal' pointer that cannot be loaded? Boris From finjulhich at gmail.com Tue Jul 21 13:06:22 2015 From: finjulhich at gmail.com (MM) Date: Tue Jul 21 13:06:31 2015 Subject: [odb-users] polymorphic inheritance, typeid, odb::object_not_persistent In-Reply-To: References: Message-ID: On 21 July 2015 at 16:15, Boris Kolpackov wrote: > Hi, > > MM writes: > > > I get this exception: odb::object_not_persistent > > > > The intent is to load from the database all the persistent objects (the > > derived) from the Base table, and assign them a concrete derived instance > > (D1...D10) according to the typeid, and populate the name field > > > > I don't know if this is expected to work, and what is the correction if > > something is wrong. > > Yes, the polymorpism part is expected to work, and from what you have > shown (i.e., no database mapping pragmas -- always a good idea to include), > I don't see anything wrong. Perhaps it is that 'cal' pointer that cannot > be loaded? > > Boris > Apologies for missing the pragmas and a function from Base: class Base { public: const std::string& name() const; void name(const std::string&); void sometype(const sometype&); const sometype& sometype() const; virtual ~Base() =default; protected: Base() = default; Base(const std::string&, const sometype&); private: std::string name_; const sometype* cal_; }; The pragmas are in a separate odb specific header: namespace NS { #pragma db object(Base) polymorphic definition #pragma db member(Base::name_) id access(name) #pragma db member(Base::cal_) get(&this.sometype()) set(this.sometype (*(?))) #pragma db object(D1) definition #pragma db object(D2) definition .... #pragma db object(D10) definition } Another odb header has the pragma for sometype namespace NS { #pragma db object(sometype) table("OtherTable") definition #pragma db member(sometype::name_) id } Within the same transaction, I do successfully load 11(all) of the 'sometype': I get raw pointers from the load() calls (same as above), and I own these pointers with a boost::ptr_vector. _After_ the 'sometype' are loaded, I, then, load the Base items. But that fails. Am I breaking the relationship for odb to connect the dots somehow? Is there some sort of debugging I can trigger to detect the issue? Thanks Boris, From pahlevan at gmail.com Wed Jul 22 07:08:44 2015 From: pahlevan at gmail.com (Mohammad Pahlevan) Date: Wed Jul 22 07:09:21 2015 Subject: [odb-users] FOREIGN KEY is commented (one-to-many) Message-ID: Dear Sir, in SQL Script that Generated by odb compiler, FOREIGN KEY for one-to-many Relation is Commented. Who can I enable this relation? ------------------------------------------------------------- -- odb command odb -d mssql --generate-query --generate-schema employee.hxx -------------------------------------------------------------- -- sql generated /* This file was generated by ODB, object-relational mapping (ORM) * compiler for C++. */ IF OBJECT_ID('employee', 'U') IS NOT NULL DROP TABLE [employee]; GO IF OBJECT_ID('employer', 'U') IS NOT NULL DROP TABLE [employer]; GO CREATE TABLE [employer] ( [id] INT NOT NULL PRIMARY KEY IDENTITY, [val1] INT NOT NULL, [val2] INT NOT NULL, [val3] INT NOT NULL, [val4] INT NOT NULL); GO CREATE TABLE [employee] ( [id] INT NOT NULL PRIMARY KEY, [name1] VARCHAR(512) NOT NULL, [name2] VARCHAR(512) NOT NULL, [employer] INT NOT NULL /* CONSTRAINT [employee_employer_fk] FOREIGN KEY ([employer]) REFERENCES [employer] ([id]) */); GO ------------------------------------------------------------------------------------------------------ -- employee.hxx file #ifndef EMPLOYEE_HXX #define EMPLOYEE_HXX #include #include #include #include using std::tr1::shared_ptr; using std::tr1::weak_ptr; class employee; #pragma db object class employer { private: friend class odb::access; employer () {} #pragma db id auto int id_; int val1_; int val2_; int val3_; int val4_; #pragma db not_null inverse(employer_) std::vector > employees_; }; #pragma db object class employee { public: employee (); employee (const std::string&); private: friend class odb::access; #pragma db id int id_; std::string name1_; std::string name2_; #pragma db not_null shared_ptr employer_; }; #endif // EMPLOYEE_HXX TNX From boris at codesynthesis.com Wed Jul 22 10:37:47 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 22 10:37:49 2015 Subject: [odb-users] FOREIGN KEY is commented (one-to-many) In-Reply-To: References: Message-ID: Hi Mohammad, Mohammad Pahlevan writes: > in SQL Script that Generated by odb compiler, FOREIGN KEY for one-to-many > Relation is Commented. Quoting the ODB compiler command line manual (man pages): --fkeys-deferrable-mode m Use constraint checking mode m in foreign keys generated for object relationships. Valid values for this option are not_deferrable, immediate, and deferred (default). MySQL and SQL Server do not support deferrable foreign keys and for these databases such keys are generated commented out. Other foreign keys generated by the ODB compiler (such as the ones used to support containers and polymorphic hierarchies) are always generated as not deferrable. Note also that if you use either not_deferrable or immediate mode, then the order in which you persist, update, and erase objects within a transaction becomes important. Boris From boris at codesynthesis.com Wed Jul 22 10:43:46 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 22 10:43:47 2015 Subject: [odb-users] polymorphic inheritance, typeid, odb::object_not_persistent In-Reply-To: References: Message-ID: Hi, MM writes: > Within the same transaction, I do successfully load 11(all) of the > 'sometype': > I get raw pointers from the load() calls (same as above), and I own these > pointers with a boost::ptr_vector. > _After_ the 'sometype' are loaded, I, then, load the Base items. But that > fails. What if you try to load D1..D10 using load() rather than query(), specifying either Base or the concrete types (both should work). This way you can narrow it down to which one fails to load (if any; it can also be that load() will work and there is something special about query()). > Am I breaking the relationship for odb to connect the dots somehow? Not that I can see. > Is there some sort of debugging I can trigger to detect the issue? Yes, in fact, enabling statement tracing in such situations can be very helpful. Try: t.tracer (stderr_tracer); This way we will at least know where exactly things go south. Boris From finjulhich at gmail.com Wed Jul 22 11:46:41 2015 From: finjulhich at gmail.com (MM) Date: Wed Jul 22 11:46:49 2015 Subject: [odb-users] polymorphic inheritance, typeid, odb::object_not_persistent In-Reply-To: References: Message-ID: On 22 July 2015 at 15:43, Boris Kolpackov wrote: > Hi, > > MM writes: > > > Within the same transaction, I do successfully load 11(all) of the > > 'sometype': > > I get raw pointers from the load() calls (same as above), and I own these > > pointers with a boost::ptr_vector. > > _After_ the 'sometype' are loaded, I, then, load the Base items. But that > > fails. > > What if you try to load D1..D10 using load() rather than query(), > specifying either Base or the concrete types (both should work). > This way you can narrow it down to which one fails to load (if > any; it can also be that load() will work and there is something > special about query()). > > > > Am I breaking the relationship for odb to connect the dots somehow? > > Not that I can see. > > > > Is there some sort of debugging I can trigger to detect the issue? > > Yes, in fact, enabling statement tracing in such situations can be > very helpful. Try: > > t.tracer (stderr_tracer); > > This way we will at least know where exactly things go south. > > Boris > The first load succeeds for 'sometype' as mentioned before, and the sql queries are traced out. Then, the code that fails: { auto res = db.query(); std::size_t cnt = 0u; for (auto i=std::begin(res); i!=std::end(res); ++i, ++cnt) some_function( i.load() ); std::cout<<" "< References: Message-ID: On 22 July 2015 at 16:46, MM wrote: > On 22 July 2015 at 15:43, Boris Kolpackov wrote: > >> Hi, >> >> MM writes: >> >> > Within the same transaction, I do successfully load 11(all) of the >> > 'sometype': >> > I get raw pointers from the load() calls (same as above), and I own >> these >> > pointers with a boost::ptr_vector. >> > _After_ the 'sometype' are loaded, I, then, load the Base items. But >> that >> > fails. >> >> What if you try to load D1..D10 using load() rather than query(), >> specifying either Base or the concrete types (both should work). >> This way you can narrow it down to which one fails to load (if >> any; it can also be that load() will work and there is something >> special about query()). >> >> >> > Am I breaking the relationship for odb to connect the dots somehow? >> >> Not that I can see. >> >> >> > Is there some sort of debugging I can trigger to detect the issue? >> >> Yes, in fact, enabling statement tracing in such situations can be >> very helpful. Try: >> >> t.tracer (stderr_tracer); >> >> This way we will at least know where exactly things go south. >> >> Boris >> > > The first load succeeds for 'sometype' as mentioned before, and the sql > queries are traced out. > > Then, the code that fails: > > { > auto res = db.query(); > std::size_t cnt = 0u; > for (auto i=std::begin(res); i!=std::end(res); ++i, ++cnt) > some_function( i.load() ); > std::cout<<" "< } > > yields these SQL stmts: > > SELECT "Base"."name", "Base"."typeid", "Base"."cal" FROM "Base" > SELECT "OtherTable"."name" FROM "OtherTable" WHERE "OtherTable"."name"=? > object not persistent > terminate called after throwing an instance of 'odb::object_not_persistent' > what(): object not persistent > > some of the Base.cal are NULL in the database. > > obviously I would need to change my > > #pragma db member(Base::cal_) get(&this.sometype()) set(this.sometype > (*(?))) > > How to say: if NULL in the database, then don't sent the cal member? > I have put in a if statement in the set() modifier. Indeed the cal field was pointing to a inexisting entry in the other table. I need to review the referential integrity items about sqlite in the odb manual. thanks, From boris at codesynthesis.com Mon Jul 27 14:06:37 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 27 14:06:34 2015 Subject: [odb-users] Name clash when using nested value types with pointer In-Reply-To: <37edc0a951304a1b93788cca580374ac@QEX.qosmotec.com> References: <37edc0a951304a1b93788cca580374ac@QEX.qosmotec.com> Message-ID: <20150727180637.GB9452@codesynthesis.com> Hi Marcel, Marcel Nehring writes: > I discovered an issue with the ODB compiler today. Fixed, thanks for the report and the test case! > [...] it would be nice if you could again provide a pre-release > binary package including the fix. Here you go: http://codesynthesis.com/~boris/tmp/odb/pre-release/a1/ Let me know if there are any issues. Boris