From marco.craveiro at gmail.com Wed Mar 1 06:30:36 2017 From: marco.craveiro at gmail.com (Marco Craveiro) Date: Wed Mar 1 06:30:51 2017 Subject: [odb-users] BLOBs and multi-database In-Reply-To: References: Message-ID: Hi Boris, > You are probably looking for the database pragma prefix (introduction > to Chapter 16, "Multi-Database Support"): > > #pragma db pgsql:type("BYTEA") oracle:type("BLOB") > std::vector data; Yep that was exactly it, thanks very much. Cheers -- Marco Craveiro MD, Domain Driven Consulting about: http://about.me/marcocraveiro blog: http://mcraveiro.blogspot.co.uk twitter: https://twitter.com/MarcoCraveiro That the Ideas are themselves manifestations (of the Idea-Idea) and that the Idea-Idea is a-kind-of Manifestation-Idea?which is a-kind-of itself, so that the system is completely self-describing? would have been appreciated by Plato as an extremely practical joke [Plato]. -- Alan Key From boris at codesynthesis.com Wed Mar 1 11:12:30 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Mar 1 11:12:39 2017 Subject: [odb-users] Inverse and composite Id In-Reply-To: References: Message-ID: Hi Sean, Sean Clarke writes: > class A { > > #pragma db value > struct Id { > int a; > int b; > } > > #pragma db id > Id m_id; > > #pragma db value_not_null > std::shared_ptr m_b; > > }; > > > class B { > using id_t = std::uint32_t; > > #pragma db id > id_t m_id; > > #pragma db inverse(m_b) > std::vector> m_as; > }; > > //odb_gen/A-odb.hxx:385:70: error: ?image_type? in ?class > odb::access::composite_value_traits? does not > name a type The error suggests that you have it the other way around (Id is in B, not A, and A points to B). Assuming this is the case, my guess would be that the header that contains A doesn't include the one containing B. See Section 6.3, "Circular Relationships" in the manual for details on the issue and possible solutions. Boris From boris at codesynthesis.com Wed Mar 1 11:22:22 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Mar 1 11:22:30 2017 Subject: [odb-users] Using prefetch with Oracle In-Reply-To: References: <20170213135652.GA22900@codesynthesis.com> Message-ID: Hi Marco, Marco Craveiro writes: > On the plus side I am cataloguing the adventure under a series of blog > posts - [1], [2] so far - which may (or may not) help other Oracle / > ODB users. Good stuff. I need to setup an Oracle 11 VM soon. Now I know which guide I will use ;-). Boris From sean.clarke at sec-consulting.co.uk Wed Mar 1 15:41:49 2017 From: sean.clarke at sec-consulting.co.uk (Sean Clarke) Date: Wed Mar 1 15:42:01 2017 Subject: [odb-users] Inverse and composite Id In-Reply-To: References: Message-ID: On 1 March 2017 at 16:12, Boris Kolpackov wrote: > The error suggests that you have it the other way around (Id is in B, not > A, and A points to B). Assuming this is the case, my guess would be that > the header that contains A doesn't include the one containing B. See > Section 6.3, "Circular Relationships" in the manual for details on the > issue and possible solutions. > ?Hmm... OK, thanks Boris. I have double checked (obviously because my classes are not really called A or B)? and the case above is a reflection of what I am doing, but I did report the error in the wrong file (sorry): > //odb_gen/B-odb.hxx:385:70: error: ?image_type? in ?class odb::access::composite_value_traits? does not name a type composite_value_traits< ::A::Id, id_pgsql >::image_type value_value; Thanks for the info on circular relationships, I have followed your instructions (although I was achieving the same result before) and I still get the same problem. Will keep on playing and investigating.... Regards Sean Clarke From anhu.com at gmail.com Thu Mar 2 03:53:46 2017 From: anhu.com at gmail.com (Hu An) Date: Thu Mar 2 05:28:17 2017 Subject: [odb-users] Question about supported compilers (Visual Studio 2015) Message-ID: Hi! The page "Supported Platforms and C++ Compilers" ( http://www.codesynthesis.com/products/odb/platforms.xhtml) does not list Visual Studio 2015. Can I still use ODB technology, if our solution is entirely a VS 2015 solution or are there problems to expect? Thanks for your answer, A. Hu From boris at codesynthesis.com Thu Mar 2 08:38:55 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Mar 2 08:39:04 2017 Subject: [odb-users] Inverse and composite Id In-Reply-To: References: Message-ID: Hi Sean, Sean Clarke writes: > Thanks for the info on circular relationships, I have followed your > instructions (although I was achieving the same result before) and I still > get the same problem. > > Will keep on playing and investigating.... If you can send a small but complete test case (i.e., the two headers and how you compiled them), I can take a look. Boris From boris at codesynthesis.com Thu Mar 2 08:41:56 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Mar 2 08:42:05 2017 Subject: [odb-users] Question about supported compilers (Visual Studio 2015) In-Reply-To: References: Message-ID: Hi, Hu An writes: > The page "Supported Platforms and C++ Compilers" does not list Visual > Studio 2015. Can I still use ODB technology, if our solution is > entirely a VS 2015 solution or are there problems to expect? No, it should work. I believe quite a few people are using ODB with VS 2015 by simply converting the solution for the previous version. We will also add official support for VS 2015 (and 2017) in the next release, which should be out "real soon now" (famous last words, I know). Boris From sean.clarke at sec-consulting.co.uk Thu Mar 2 17:28:52 2017 From: sean.clarke at sec-consulting.co.uk (Sean Clarke) Date: Thu Mar 2 17:29:06 2017 Subject: [odb-users] Inverse and composite Id In-Reply-To: References: Message-ID: Still investigating.... it definitely is something to do with the: #pragma db value struct Id { int a; int b; } if I comment that out and add: using Id = std::uint32_t; and amend the operator< appropriately it seems to work. Regards Sean Clarke On 1 March 2017 at 16:12, Boris Kolpackov wrote: > Hi Sean, > > Sean Clarke writes: > > > class A { > > > > #pragma db value > > struct Id { > > int a; > > int b; > > } > > > > #pragma db id > > Id m_id; > > > > #pragma db value_not_null > > std::shared_ptr m_b; > > > > }; > > > > > > class B { > > using id_t = std::uint32_t; > > > > #pragma db id > > id_t m_id; > > > > #pragma db inverse(m_b) > > std::vector> m_as; > > }; > > > > //odb_gen/A-odb.hxx:385:70: error: ?image_type? in ?class > > odb::access::composite_value_traits? does > not > > name a type > > The error suggests that you have it the other way around (Id is in B, not > A, and A points to B). Assuming this is the case, my guess would be that > the header that contains A doesn't include the one containing B. See > Section 6.3, "Circular Relationships" in the manual for details on the > issue and possible solutions. > > Boris > From marco.craveiro at gmail.com Fri Mar 3 03:22:53 2017 From: marco.craveiro at gmail.com (Marco Craveiro) Date: Fri Mar 3 03:23:06 2017 Subject: [odb-users] Question about supported compilers (Visual Studio 2015) In-Reply-To: References: Message-ID: Hi, >> The page "Supported Platforms and C++ Compilers" does not list Visual >> Studio 2015. Can I still use ODB technology, if our solution is >> entirely a VS 2015 solution or are there problems to expect? > > No, it should work. I believe quite a few people are using ODB with > VS 2015 by simply converting the solution for the previous version. > > We will also add official support for VS 2015 (and 2017) in the > next release, which should be out "real soon now" (famous last > words, I know). For what it's worth, I used ODB against 2015 with Oracle and I did exactly what Boris suggests there and it worked fine. Cheers -- Marco Craveiro MD, Domain Driven Consulting about: http://about.me/marcocraveiro blog: http://mcraveiro.blogspot.co.uk twitter: https://twitter.com/MarcoCraveiro That the Ideas are themselves manifestations (of the Idea-Idea) and that the Idea-Idea is a-kind-of Manifestation-Idea?which is a-kind-of itself, so that the system is completely self-describing? would have been appreciated by Plato as an extremely practical joke [Plato]. -- Alan Key From c.sell at byterefinery.de Sun Mar 5 16:37:42 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Sun Mar 5 16:37:51 2017 Subject: [odb-users] collection mapping error Message-ID: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> Hello all, I have a simple std::vector collection mapping which is controlled by a section. I also have traits implementations for the QImage type. The database table generated from the mappings has the following columns: object_id index value with object_id referring back to the main object table. Now, when I try to update the container, I get an exception stating that the object was already persistent. This happens during the first insert into the empty collection table, so it cannot be true. Further investigation shows that the error is in fact a constraint error, caused by the fact that no value is bound to the object_id column. Stepping to the ODB generated code shows that indeed values for 'index' and 'value' are supplied, but not for object_id What can I do? regards, Christian From boris at codesynthesis.com Mon Mar 6 03:44:05 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Mar 6 03:44:14 2017 Subject: [odb-users] collection mapping error In-Reply-To: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> Message-ID: Hi Christian, c.sell@byterefinery.de writes: > I have a simple std::vector collection mapping which is controlled > by a section. We had a few bugs fixed in the section implementation. Does everything work if you get rid of the section? Boris From c.sell at byterefinery.de Mon Mar 6 04:01:18 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Mon Mar 6 04:01:27 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> Message-ID: <20170306090118.Horde.oyO72rcLugysh9uAzZ2fNhp@webmail.byterefinery.de> Hello Boris, unfortunately no. I just removed the section and the issue is exactly the same. The only remaining unusual thing about the mapping I can detect is the fact that the collection elements are of a type that ODB doesn't directly support. Is there something I could have done wrong in my mapping traits implementation which could cause this? thanks, Christian Zitat von Boris Kolpackov : > Hi Christian, > > c.sell@byterefinery.de writes: > >> I have a simple std::vector collection mapping which is controlled >> by a section. > > We had a few bugs fixed in the section implementation. Does everything work > if you get rid of the section? > > Boris From c.sell at byterefinery.de Mon Mar 6 04:05:36 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Mon Mar 6 04:05:44 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> Message-ID: <20170306090536.Horde.dJszFfqXunR7xI087S4GkTb@webmail.byterefinery.de> below is the generated code that is executed immediately before the sql statement fails, and of which which I assume that is provides the parameter values. object_id is suspiciously missing: void access::object_traits_impl< ::rentalapp::Damage, id_sqlite >::odb_pictures_traits:: init (data_image_type& i, index_type* j, const value_type& v) { using namespace sqlite; statement_kind sk (statement_insert); ODB_POTENTIALLY_UNUSED (sk); bool grew (false); // index // if (j != 0) { bool is_null (false); sqlite::value_traits< index_type, sqlite::id_integer >::set_image ( i.index_value, is_null, *j); i.index_null = is_null; } // value // { bool is_null (false); std::size_t cap (i.value_value.capacity ()); sqlite::value_traits< value_type, sqlite::id_blob >::set_image ( i.value_value, i.value_size, is_null, v); i.value_null = is_null; grew = grew || (cap != i.value_value.capacity ()); } if (grew) i.version++; } Zitat von Boris Kolpackov : > Hi Christian, > > c.sell@byterefinery.de writes: > >> I have a simple std::vector collection mapping which is controlled >> by a section. > > We had a few bugs fixed in the section implementation. Does everything work > if you get rid of the section? > > Boris From c.sell at byterefinery.de Mon Mar 6 04:12:49 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Mon Mar 6 04:12:56 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> Message-ID: <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> also, I am on 2.5.0-a11 using sqlite as backend. I had to go to 2.5 due to another bug I ran into btw, I will be migrating my app to windows soon, and it just dawns on me that I might have issues getting a suitable precompiled version (don't even remember where I got the 2.5.0-a11 from). As far as I can tell, the website has nothing. Any help? thanks, Christian Zitat von Boris Kolpackov : > Hi Christian, > > c.sell@byterefinery.de writes: > >> I have a simple std::vector collection mapping which is controlled >> by a section. > > We had a few bugs fixed in the section implementation. Does everything work > if you get rid of the section? > > Boris From boris at codesynthesis.com Mon Mar 6 05:33:47 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Mar 6 05:33:56 2017 Subject: [odb-users] collection mapping error In-Reply-To: <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> Message-ID: Hi Christian, 1. Can you create a test case that reproduces this problem? Preferably with std::vector used as a blob value. 2. Once we solve this, I can build you pre-release binary for Windows. Boris From c.sell at byterefinery.de Mon Mar 6 07:57:34 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Mon Mar 6 07:57:43 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> Message-ID: <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> Hello Boris, I created a testcase using this mapping: typedef std::vector buffer; #pragma db value(buffer) type("BLOB") #pragma db object struct Damage { #pragma db id auto long id_; std::string name; std::vector pictures; }; but it did not reproduce ther error. However, I have been able to track the issue down a little further. It appears that the binding code is not executed because in function insert(), the data_binding_test_version () check fails: if (sts.data_binding_test_version ()) { const binding& id (sts.id_binding ()); bind (sts.data_bind (), id.bind, id.count, di); sts.data_binding_update_version (); } in my test case program, the if branch is entered once for the collection object. With my target app, it isn't ever HTH to help me Chris From boris at codesynthesis.com Mon Mar 6 08:26:28 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Mar 6 08:26:37 2017 Subject: [odb-users] collection mapping error In-Reply-To: <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> Message-ID: Hi Christian, c.sell@byterefinery.de writes: > It appears that the binding code is not executed because in function > insert(), the data_binding_test_version () check fails: > > if (sts.data_binding_test_version ()) > { > const binding& id (sts.id_binding ()); > bind (sts.data_bind (), id.bind, id.count, di); > sts.data_binding_update_version (); > } > > > in my test case program, the if branch is entered once for the collection > object. With my target app, it isn't ever Yeah, that's fishy. Smells like memory corruption. You can try two things: 1. Try to plug your QImage implementation into the test case. The idea is basically to try to "bring" the test case a step at a time closer to your application and see what triggers the change. 2. Try to run something like valgrind on your application (or the test case if you manage to make it fail). Boris From c.sell at byterefinery.de Mon Mar 6 09:58:19 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Mon Mar 6 09:58:27 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> Message-ID: <20170306145819.Horde.q6qu9ZfmjHz0haIrGymowyB@webmail.byterefinery.de> I don't think this is a memory overrun. All values are normal (0 or 1), all pointers are valid Zitat von Boris Kolpackov : > Hi Christian, > > c.sell@byterefinery.de writes: > >> It appears that the binding code is not executed because in function >> insert(), the data_binding_test_version () check fails: >> >> if (sts.data_binding_test_version ()) >> { >> const binding& id (sts.id_binding ()); >> bind (sts.data_bind (), id.bind, id.count, di); >> sts.data_binding_update_version (); >> } >> >> >> in my test case program, the if branch is entered once for the collection >> object. With my target app, it isn't ever > > Yeah, that's fishy. Smells like memory corruption. You can try two things: > > 1. Try to plug your QImage implementation into the test case. The idea is > basically to try to "bring" the test case a step at a time closer to > your application and see what triggers the change. > > 2. Try to run something like valgrind on your application (or the test > case if you manage to make it fail). > > Boris From c.sell at byterefinery.de Mon Mar 6 10:19:43 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Mon Mar 6 10:19:51 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> Message-ID: <20170306151943.Horde.mdgtE3Y49cHVKvwsoLKjVCl@webmail.byterefinery.de> Hi Boris, it seems my assumptions were wrong. If I adapt the example to the exact same sequence of operations as the productive code (first a select, then an insert), it shows the exact same state at the respective points. bind() seems to be only executed once even across statements, and the data_binding_test_version() check always fails afterwards (in both my testcases, that is) This leads me to the assumption that the issue lies not in binding, but rather in writing to the once bound memory area. I am back at point 0. Appreciate any guidance Christian Zitat von Boris Kolpackov : > Hi Christian, > > c.sell@byterefinery.de writes: > >> It appears that the binding code is not executed because in function >> insert(), the data_binding_test_version () check fails: >> >> if (sts.data_binding_test_version ()) >> { >> const binding& id (sts.id_binding ()); >> bind (sts.data_bind (), id.bind, id.count, di); >> sts.data_binding_update_version (); >> } >> >> >> in my test case program, the if branch is entered once for the collection >> object. With my target app, it isn't ever > > Yeah, that's fishy. Smells like memory corruption. You can try two things: > > 1. Try to plug your QImage implementation into the test case. The idea is > basically to try to "bring" the test case a step at a time closer to > your application and see what triggers the change. > > 2. Try to run something like valgrind on your application (or the test > case if you manage to make it fail). > > Boris From c.sell at byterefinery.de Mon Mar 6 11:15:09 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Mon Mar 6 11:15:17 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> Message-ID: <20170306161509.Horde.Z5pORhT1Ba7-iJEmoMT5vn0@webmail.byterefinery.de> Hello Boris, I have been able to boil down the error to what I consider the simplest form. It requires the collection to hold QImage and therefore depends on my custom profile. However, I seriously doubt that the traits code itself is the problem, as almost none of it ever gets executed. The test program simply tries to persist one object which holds a vector. The image itself is invalid, and therefore gets translated to a NULL marker. There is no data copying etc. performed. However, the very first insert leads to said object_already_persisten error. if anything, this error is in error. regards, Christian -------------- next part -------------- A non-text attachment was scrubbed... Name: odbdemo.tar.gz Type: application/x-compressed-tar Size: 5468 bytes Desc: not available Url : http://codesynthesis.com/pipermail/odb-users/attachments/20170306/42eabc7e/odbdemo.tar-0001.bin From c.sell at byterefinery.de Mon Mar 6 12:10:36 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Mon Mar 6 12:10:45 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> Message-ID: <20170306171036.Horde.3PzqfOyuMCepX88md5ePl1X@webmail.byterefinery.de> ok, found it. The issue lies in the line my traits implementation that says is_null = v.isNull(); meaning, the column ist marked NULL if QImage#isNull() returns true. Which, in my mind, makes a lot of sense. However, the generated DDL marks the column as NOT NULL, and the vector standard traits implementation always at least writes an empty column. Now someone explain to me why collection items can never be NULL. Anyway, while this is so, any traits implementation that generates NULL values is not suitable for value collections regards, Chris Zitat von Boris Kolpackov : > Hi Christian, > > c.sell@byterefinery.de writes: > >> It appears that the binding code is not executed because in function >> insert(), the data_binding_test_version () check fails: >> >> if (sts.data_binding_test_version ()) >> { >> const binding& id (sts.id_binding ()); >> bind (sts.data_bind (), id.bind, id.count, di); >> sts.data_binding_update_version (); >> } >> >> >> in my test case program, the if branch is entered once for the collection >> object. With my target app, it isn't ever > > Yeah, that's fishy. Smells like memory corruption. You can try two things: > > 1. Try to plug your QImage implementation into the test case. The idea is > basically to try to "bring" the test case a step at a time closer to > your application and see what triggers the change. > > 2. Try to run something like valgrind on your application (or the test > case if you manage to make it fail). > > Boris From boris at codesynthesis.com Tue Mar 7 07:23:49 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Mar 7 07:24:00 2017 Subject: [odb-users] collection mapping error In-Reply-To: <20170306171036.Horde.3PzqfOyuMCepX88md5ePl1X@webmail.byterefinery.de> References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> <20170306171036.Horde.3PzqfOyuMCepX88md5ePl1X@webmail.byterefinery.de> Message-ID: Hi Christian, c.sell@byterefinery.de writes: > However, the generated DDL marks the column as NOT NULL, That's the default. You can override (i.e., allow NULLs) with: #pragma db value_null > and the vector standard traits implementation always at least > writes an empty column. Right, since std::vector<> has no notion of a NULL value. > Now someone explain to me why collection items can never be NULL. Anyway, > while this is so, any traits implementation that generates NULL values is > not suitable for value collections None of this is correct/makes sense. But I hope the above explanations will help (if not, please read the manual; we both could have saved a lot of time if you did so from the beginning). Boris From c.sell at byterefinery.de Tue Mar 7 08:26:04 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Tue Mar 7 08:26:13 2017 Subject: [odb-users] collection mapping error In-Reply-To: References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> <20170306171036.Horde.3PzqfOyuMCepX88md5ePl1X@webmail.byterefinery.de> Message-ID: <20170307132604.Horde.8W9SmOxi71AvPAz7plskcrQ@webmail.byterefinery.de> Hi Boris, > Right, since std::vector<> has no notion of a NULL value. It is your choice to represent an empty vector by an empty byte sequence. It was my choice to represent an empty image by a NULL value. This is only dealing with how they are stored, the collection that holds them still sees the empty value > None of this is correct/makes sense. But I hope the above explanations > will help (if not, please read the manual; we both could have saved a > lot of time if you did so from the beginning). Sorry, but I dont see how reading the manual would have helped. I was faced with an error message stating "object already persistent", when in fact it was a constraint violation caused by a non-obvious (and undocumented) interdependence between the default data model (NOT NULL constraints on collection value columns) and the traits implementation (which should not set the NULL marker if used with the default data model). I suggest an amendment to the documentation that points to the fact that the default data model for collections imposes NOT NULL constraints (I may have overread that). And maybe even some hint on how to deal with is_null in traits implementations (I dont think I overread that, I searched thoroughly for docs and only found a reference to sample code). Anyway, not an issue, this is a free lunch. I just don't want to "not make sense". May I still take you up on your offer regarding the pre-release build for windows? regards, Christian From lloydkl.tech at gmail.com Tue Mar 7 23:42:40 2017 From: lloydkl.tech at gmail.com (Lloyd) Date: Tue Mar 7 23:42:52 2017 Subject: [odb-users] Compile error , Memory leak detection enabled Message-ID: Hi, When I compile the application with Visual Studio CRT with memory leak detection (https://msdn.microsoft.com/en-us/library/x98tx3cf.aspx) I get the following error from ODB. Is it a problem associated with ODB? Libraries\odb\libodb-2.4.0\odb/pointer-traits.hxx(156): error C2059: syntax error: 'constant' Libraries\odb\libodb-2.4.0\odb/pointer-traits.hxx(160): note: see reference to class template instantiation 'odb::pointer_traits' being compiled Thanks, Lloyd From c.sell at byterefinery.de Wed Mar 8 06:41:43 2017 From: c.sell at byterefinery.de (c.sell@byterefinery.de) Date: Wed Mar 8 08:42:58 2017 Subject: [odb-users] collection mapping error In-Reply-To: <20170307132604.Horde.8W9SmOxi71AvPAz7plskcrQ@webmail.byterefinery.de> References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> <20170306171036.Horde.3PzqfOyuMCepX88md5ePl1X@webmail.byterefinery.de> <20170307132604.Horde.8W9SmOxi71AvPAz7plskcrQ@webmail.byterefinery.de> Message-ID: <20170308114143.Horde.h7545XASpxta-ccrkhUqJJG@webmail.byterefinery.de> Hello, so, I've done my reading, for the record. NULL value sematics are indeed documented. Assuming not-null semantics for values is a conceptual decision, which is also documented and circumventable (odb::nullable etc.) the fact that the exception states "object already persistent" rather than "constraint violation" remains misleading. the fact that the is_null parameter in the set_image function of value_traits implementations should be used with caution might deserve mentioning. All examples simply set it to false, and never say why. Apart from the above, the more I read into ODB, the more impressed I am. Beautiful software, very capable and quite well documented. I wrote a pretty complete O/R mapper for Smalltalk almost 20 years ago and know the Java bunch (Hibernate, JPA). So I feel I can make that statement (and some others) regards, Christian Zitat von c.sell@byterefinery.de: > Hi Boris, > >> Right, since std::vector<> has no notion of a NULL value. > > It is your choice to represent an empty vector by an empty > byte sequence. It was my choice to represent an empty image by a > NULL value. This is only dealing with how they are stored, the > collection that holds them still sees the empty value > >> None of this is correct/makes sense. But I hope the above explanations >> will help (if not, please read the manual; we both could have saved a >> lot of time if you did so from the beginning). > > Sorry, but I dont see how reading the manual would have helped. I > was faced with an error message stating "object already persistent", > when in fact it was a constraint violation caused by a non-obvious > (and undocumented) interdependence between the default data model > (NOT NULL constraints on collection value columns) and the traits > implementation (which should not set the NULL marker if used with > the default data model). > > I suggest an amendment to the documentation that points to the fact > that the default data model for collections imposes NOT NULL > constraints (I may have overread that). And maybe even some hint on > how to deal with is_null in traits implementations (I dont think I > overread that, I searched thoroughly for docs and only found a > reference to sample code). > > Anyway, not an issue, this is a free lunch. I just don't want to > "not make sense". > > May I still take you up on your offer regarding the pre-release > build for windows? > > regards, > Christian From boris at codesynthesis.com Wed Mar 8 08:50:23 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Mar 8 08:50:32 2017 Subject: [odb-users] collection mapping error In-Reply-To: <20170308114143.Horde.h7545XASpxta-ccrkhUqJJG@webmail.byterefinery.de> References: <20170305213742.Horde.v_xEXGL6PFPkmOrc7zNsAdh@webmail.byterefinery.de> <20170306091249.Horde.qFcvEIuC_nqXG6F6HuRljtr@webmail.byterefinery.de> <20170306125734.Horde.UoTXGi-GOSjxfSHX7c6-nWt@webmail.byterefinery.de> <20170306171036.Horde.3PzqfOyuMCepX88md5ePl1X@webmail.byterefinery.de> <20170307132604.Horde.8W9SmOxi71AvPAz7plskcrQ@webmail.byterefinery.de> <20170308114143.Horde.h7545XASpxta-ccrkhUqJJG@webmail.byterefinery.de> Message-ID: Hi Christian, c.sell@byterefinery.de writes: > so, I've done my reading, for the record. Thanks, I appreciate it. > the fact that the exception states "object already persistent" rather than > "constraint violation" remains misleading. The reason for it is described in Subsection 18.5.4, "Constraint Violations" of Section 18.5, "SQLite Limitations". Generally, it makes sense to read through that whole section for every database that one is using. > Apart from the above, the more I read into ODB, the more impressed I am. > Beautiful software, very capable and quite well documented. I wrote a pretty > complete O/R mapper for Smalltalk almost 20 years ago and know the Java > bunch (Hibernate, JPA). So I feel I can make that statement (and some > others) Thanks, I appreciate the kind words. BTW, a pre-release build for Windows is available here: http://codesynthesis.com/~boris/tmp/odb/pre-release/a11/ Boris From boris at codesynthesis.com Wed Mar 8 08:57:35 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Mar 8 08:57:45 2017 Subject: [odb-users] Compile error , Memory leak detection enabled In-Reply-To: References: Message-ID: Hi Lloyd, Lloyd writes: > When I compile the application with Visual Studio CRT with memory leak > detection (https://msdn.microsoft.com/en-us/library/x98tx3cf.aspx) I get > the following error from ODB. Is it a problem associated with ODB? > > Libraries\odb\libodb-2.4.0\odb/pointer-traits.hxx(156): error C2059: syntax > error: 'constant' > Libraries\odb\libodb-2.4.0\odb/pointer-traits.hxx(160): note: see reference > to class template instantiation 'odb::pointer_traits' being compiled I think this is a problem associated with the "Visual Studio CRT with memory leak detection". The line the error points to looks like this: free (void* p) There is no mentioning of name 'constant'. My suspicion is that this leak detection build uses macro hackery to redefine some symbols (like 'free', which is not really legal per the C++ standard). You may want to report this to Microsoft (and/or use some more modern memory leak detector). Boris From odb at a-cunningham.com Thu Mar 9 18:13:46 2017 From: odb at a-cunningham.com (Andrew Cunningham) Date: Thu Mar 9 18:14:00 2017 Subject: [odb-users] erase of object in section Message-ID: Hi Boris, I have an object with members as below #pragma db load(lazy) update(change) mutable odb::section masssection_; #pragma db section(masssection_) std::unique_ptr massDistribMatrix_; Before I erase the "containing" object do I need to load the section to ensure the proper erasure of the massDistribMatrix_ object? I was assuming the answer is "no". Andrew From boris at codesynthesis.com Fri Mar 10 05:16:52 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Mar 10 05:17:00 2017 Subject: [odb-users] erase of object in section In-Reply-To: References: Message-ID: Hi Andrew, Andrew Cunningham writes: > #pragma db load(lazy) update(change) > mutable odb::section masssection_; > #pragma db section(masssection_) > std::unique_ptr massDistribMatrix_; > > Before I erase the "containing" object do I need to load the section to > ensure the proper erasure of the massDistribMatrix_ object? This "containing" terminology is fuzzy. You have a pointer in massDistribMatrix_ and you have a "pointed-to" object. You can "erase" the pointer (e.g., by setting it to NULL or to point to some other object) or you can erase the pointed-to object, or, perhaps, both. Note also that these two operations are completely independent (normally; unless you use something like ON DELETE CASCADE). So what exactly do you want to "erase"? Boris From balazs.bayer at gmail.com Wed Mar 15 08:32:45 2017 From: balazs.bayer at gmail.com (=?UTF-8?Q?Bal=C3=A1zs_Bayer?=) Date: Wed Mar 15 09:05:50 2017 Subject: [odb-users] Persisting class instantiated from a template Message-ID: Hi all, I would like to persist a class instantiated from a template into an SQLite database using ODB. Lets say I have the following class in a header called *result.hpp*: template class Result { public: valuetype getValue(int i) const { return Values[i]; }; int getId() const { return Id; }; void setValue(valuetype _value, int i) { Values[i] = _value; } void setId(int _Id) { Id = _Id; } private: int Id; std::array Values;}; and I have another header file called *result-mapping.hpp* with the following content: #include "result.hpp" typedef Result ResultFloatSeven; #pragma db value(ResultFloatSeven) definition transient#pragma db member(ResultFloatSeven::getId) virtual(int) access(getId) <-- line 11#pragma db member(ResultFloatSeven::getValue) virtual(float) access(getValue) When I try to generate the database support code with the command odb --std c++11 -d sqlite --odb-prologue "#include \"result-mapping.hpp\"" --generate-query result.hpp I get the following error: result-mapping.hpp:11:57: error: unable to find suitable modifier function 'getId' What is wrong here? Thanks! Bal?zs Btw I laready posted this question on stackoverflow, but did not get any feedback until now. http://stackoverflow.com/questions/42684473/c-odb-persisting-class-instantiated-from-a-template From boris at codesynthesis.com Wed Mar 15 11:22:10 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Mar 15 11:22:19 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Bal?zs, Bal?zs Bayer writes: > typedef Result ResultFloatSeven; > #pragma db value(ResultFloatSeven) definition transient > #pragma db member(ResultFloatSeven::getId) virtual(int) access(getId) > #pragma db member(ResultFloatSeven::getValue) virtual(float) access(getValue) You are using function names for virtual member names so ODB tries to derive modifier names from these function names which is not what you want. Try to change this to: #pragma db member(ResultFloatSeven::Id_) virtual(int) #pragma db member(ResultFloatSeven::Value_) virtual(float) Also, I don't think you need to go through the virtual member route in this case. ODB should be able to map everything automatically with just: typedef Result ResultFloatSeven; #pragma db value(ResultFloatSeven) definition Boris From abv150ci at gmail.com Wed Mar 15 14:36:31 2017 From: abv150ci at gmail.com (=?UTF-8?Q?Aar=C3=B3n_Bueno_Villares?=) Date: Wed Mar 15 14:37:23 2017 Subject: [odb-users] Database schema migration Message-ID: Quote: If your object model consists of a large number of header files and you generate the database schema for each of them individually, then a changelog will be created for each of your header files. [...] The solution to both of these problems is to generate a combined database schema file and a single changelog. [...] To generate the database schema, we perform a separate invocation of the ODB compiler. This time, however, we instruct it to only generate the schema (--generate-schema-only) and produce it combined (--at-once) for all the files in our object model However, ODB has a --changelog *file *option which allows to specify your own changelog filename. Wouldn't be easier to just specify the same change log file on each invocation of the ODB compiler over the different class files? It removes an extra command and it's very easy to add a new ODB option in a typical makefile (I use a ODB_FLAGS variable to my makefile). From balazs.bayer at gmail.com Wed Mar 15 13:29:02 2017 From: balazs.bayer at gmail.com (=?UTF-8?Q?Bal=C3=A1zs_Bayer?=) Date: Thu Mar 16 04:41:30 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: When I tried with this one: #pragma db value(ResultFloatSeven) definition transient #pragma db member(ResultFloatSeven::Id_) virtual(int) #pragma db member(ResultFloatSeven::Value_) virtual(float) I got the following errors: result-mapping.hpp:12:12: error: virtual data member declaration 'Id' conflicts with a previous declaration result.hpp:41:7: info: 'Id' was previously declared here result-mapping.hpp:12:12: error: virtual data member declaration 'Id' conflicts with a previous declaration result.hpp:41:7: info: 'Id' was previously declared here and with this one: #pragma db value(ResultFloatSeven) definition the followings: result.hpp:42:31: error: data member 'Values' is private and no suitable accessor function could be automatically found result.hpp:42:31: info: consider making class 'odb::access' a friend of class 'ResultFloatSeven' result.hpp:42:31: info: or use '#pragma db get' to explicitly specify the accessor function or expression result.hpp:42:31: error: data member 'Values' is private and no suitable accessor function could be automatically found result.hpp:42:31: info: consider making class 'odb::access' a friend of class 'ResultFloatSeven' result.hpp:42:31: info: or use '#pragma db get' to explicitly specify the accessor function or expression From balazs.bayer at gmail.com Wed Mar 15 13:38:56 2017 From: balazs.bayer at gmail.com (=?UTF-8?Q?Bal=C3=A1zs_Bayer?=) Date: Thu Mar 16 04:41:30 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Sorry, the errors for #pragma db value(ResultFloatSeven) definition transient #pragma db member(ResultFloatSeven::Id_) virtual(int) #pragma db member(ResultFloatSeven::Value_) virtual(float) are: result.hpp:42:31: error: data member 'Values' is private and no suitable accessor function could be automatically found result.hpp:42:31: info: consider making class 'odb::access' a friend of class 'ResultFloatSeven' result.hpp:42:31: info: or use '#pragma db get' to explicitly specify the accessor function or expression result.hpp:42:31: error: data member 'Values' is private and no suitable accessor function could be automatically found result.hpp:42:31: info: consider making class 'odb::access' a friend of class 'ResultFloatSeven' result.hpp:42:31: info: or use '#pragma db get' to explicitly specify the accessor function or expression From boris at codesynthesis.com Thu Mar 16 12:25:00 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Mar 16 12:25:10 2017 Subject: [odb-users] Database schema migration In-Reply-To: References: Message-ID: Hi, Aar?n Bueno Villares writes: > Wouldn't be easier to just specify the same change log file on each > invocation of the ODB compiler over the different class files? Yeah, sure. It would also be pretty broken. When you regenerate the changelog, ODB makes a diff between database models. But now the difference can mean two things: something changed or this is a database model for a different subset. Boris From boris at codesynthesis.com Thu Mar 16 12:37:37 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Mar 16 12:37:46 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Bal?zs, Ok, I tried to actually compile your example with this contents of the mapping file: typedef Result ResultFloatSeven; #pragma db value(ResultFloatSeven) definition transient #pragma db member(ResultFloatSeven::Id_) virtual(int) #pragma db member(ResultFloatSeven::Value_) virtual(float) The error I get is this: mapping.hpp:7:12: error: no suitable accessor function could be automatically found for virtual data member 'Value_' mapping.hpp:7:12: info: use '#pragma db get' to explicitly specify the accessor function or expression Which makes sense, after looking at what you have: valuetype getValue(int i) const { return Values[i]; } void setValue(valuetype _value, int i) { Values[i] = _value; } These are not suitable accessors/modifiers (ODB cannot magically know what to pass for i). You need something like this: valuetype getValue() const; void setValue(valuetype) Boris From balazs.bayer at gmail.com Thu Mar 16 13:17:27 2017 From: balazs.bayer at gmail.com (=?UTF-8?Q?Bal=C3=A1zs_Bayer?=) Date: Thu Mar 16 13:24:10 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Boris, the thing is, that as Value is a std::array, and although in these code snippets its size is only 7, I am expecting to have ~1000 long arrays. And if I do this: std::array const &getValue() const { return Value; }; void setValue(const std::array &NewValue) { Value = std::move(NewValue); }; which is somehow analogue to valuetype getValue() const; void setValue(valuetype) then I guess the problem is, that when I want to change only one specific member of the Value array, I will have to construct another huge array, and pass it to setValue, which does not seem to be efficient to me. Do you have any suggestions, how to overcome this situation? Many Thanks, Balazs From boris at codesynthesis.com Fri Mar 17 11:24:17 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Mar 17 11:24:26 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Bal?zs, Bal?zs Bayer writes: > std::array const &getValue() const { return Value; }; > void setValue(const std::array &NewValue) { Value = > std::move(NewValue); }; > > then I guess the problem is, that when I want to change only one specific > member of the Value array, I will have to construct another huge array, and > pass it to setValue, which does not seem to be efficient to me. Do you have > any suggestions, how to overcome this situation? You can do by-reference access and modification: const std::array& getValue() const { return Value; }; std::array& setValue() { return Value; }; Boris From obermann.lukas at gmail.com Fri Mar 17 14:09:54 2017 From: obermann.lukas at gmail.com (Lukas Obermann) Date: Fri Mar 17 14:10:08 2017 Subject: [odb-users] Subselects in View Message-ID: Hi there, I know that it is not recommended to do complex queries with odb, but I wonder if it is possible to get a simple subselect working in a view or somewhere else. Like this simplified query: SELECT table1.name, (SELECT AVG(score) FROM table2 WHERE table2.t_id = table1.t_id) as score FROM table1 Thanks! Lukas From balazs.bayer at gmail.com Fri Mar 17 13:07:39 2017 From: balazs.bayer at gmail.com (=?UTF-8?Q?Bal=C3=A1zs_Bayer?=) Date: Mon Mar 20 09:42:04 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Boris, now its fine. Sorry for my poor c++ knowledge, and thanks very much for your help. Best regards, Bal?zs From balazs.bayer at gmail.com Sat Mar 18 06:33:45 2017 From: balazs.bayer at gmail.com (=?UTF-8?Q?Bal=C3=A1zs_Bayer?=) Date: Mon Mar 20 09:42:04 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: actually one more thing: with this: int Id = 1; std::array Values = {{0, 1, 2, 3, 4, 5, 6}}; ResultFloatSeven S(Values, Id); { std::unique_ptr db(new odb::sqlite::database( "./test.db", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); odb::transaction t(db->begin()); db->persist(S); t.commit(); } Now I get the following compilation error for the line "db->persist(S);": In file included from main.cpp:9: In file included from /usr/include/odb/sqlite/database.hxx:16: In file included from /usr/include/odb/database.hxx:23: /usr/include/odb/traits.hxx:178:5: error: implicit instantiation of undefined template 'odb::access::object_traits_impl, 5>' access::object_traits_impl, ^ /usr/include/odb/database.txx:38:5: note: in instantiation of template class 'odb::object_traits_impl, 5>' requested here object_traits::persist (*this, obj); ^ /usr/include/odb/database.ixx:160:12: note: in instantiation of function template specialization 'odb::database::persist_, 5>' requested here return persist_ (obj); ^ main.cpp:27:9: note: in instantiation of function template specialization 'odb::database::persist >' requested here db->persist(S); ^ /usr/include/odb/forward.hxx:99:11: note: template is declared here class object_traits_impl; ^ In file included from main.cpp:9: In file included from /usr/include/odb/sqlite/database.hxx:16: In file included from /usr/include/odb/database.hxx:632: /usr/include/odb/database.txx:38:18: error: incomplete definition of type 'odb::object_traits_impl, 5>' object_traits::persist (*this, obj); ~~~~~~~~~~~~~^~ /usr/include/odb/database.ixx:160:12: note: in instantiation of function template specialization 'odb::database::persist_, 5>' requested here return persist_ (obj); ^ main.cpp:27:9: note: in instantiation of function template specialization 'odb::database::persist >' requested here db->persist(S); ^ In file included from main.cpp:9: In file included from /usr/include/odb/sqlite/database.hxx:16: In file included from /usr/include/odb/database.hxx:632: /usr/include/odb/database.txx:40:29: error: no member named 'reference_cache_traits' in 'odb::object_traits_impl, 5>' typename object_traits::reference_cache_traits::position_type p ( Any idea? Thanks, Balazs From boris at codesynthesis.com Mon Mar 20 09:45:52 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Mar 20 09:46:00 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Bal?zs, Bal?zs Bayer writes: > Now I get the following compilation error for the line "db->persist(S);": Did you #include all the relevant *-odb.hxx files? If that doesn't help, please send a minimal but complete test case that reproduces the problem. Boris From boris at codesynthesis.com Mon Mar 20 12:21:02 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Mar 20 12:21:11 2017 Subject: [odb-users] Subselects in View In-Reply-To: References: Message-ID: Hi Lukas, Lukas Obermann writes: > I know that it is not recommended to do complex queries with odb, [...] Not recommended by whom? You can handle pretty much any query with an ODB native view. It may not be as convenient as for simpler queries, but it is definitely possible and not "not recommended". > SELECT table1.name, (SELECT AVG(score) FROM table2 WHERE > table2.t_id = table1.t_id) as score FROM table1 You can handle it pretty easily with a native view. You can even get fancy and do something like this: #include #pragma db object struct table1 { #pragma db id int t_id; std::string name; }; #pragma db object struct table2 { #pragma db id int t_id; int score; }; #pragma db view object(table1) object(table2) \ query("SELECT " + table1::name + ", " \ "(" \ " SELECT AVG(" + table2::score + ")" \ " FROM " + (object_traits_impl::table_name) + \ " WHERE " + (table2::t_id == table1::t_id) + \ ") AS score" \ "FROM " + (object_traits_impl::table_name)) struct view { std::string name; int avg_score; }; You can read moe about table_name here: [1] http://www.codesynthesis.com/pipermail/odb-users/2016-April/003209.html Boris From balazs.bayer at gmail.com Mon Mar 20 15:33:30 2017 From: balazs.bayer at gmail.com (=?UTF-8?Q?Bal=C3=A1zs_Bayer?=) Date: Tue Mar 21 04:38:57 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Boris, you can get the source files via these links: main.cpp result.hpp result-mapping.hpp I generate the support code and compile the whole propgram with these commands: odb --std c++11 -d sqlite -s --odb-epilogue '#include "result-mapping.hpp"' --generate-query result.hpp odb --std c++11 -d sqlite -s --generate-query result-mapping.hpp clang++ -std=c++11 -c -o result-odb.o result-odb.cxx clang++ -std=c++11 -c -o result-mapping-odb.o result-mapping-odb.cxx clang++ -std=c++11 -c -o main.o main.cpp <= at this point I get the below error message clang++ -o fut main.o result-odb.o result-mapping-odb.o -lodb-sqlite -lodb The error message is: In file included from main.cpp:8: In file included from ./result-odb.hxx:18: In file included from ./result-mapping-odb.hxx:23: /usr/include/odb/traits.hxx:178:5: error: implicit instantiation of undefined template 'odb::access::object_traits_impl, 5>' access::object_traits_impl, ^ /usr/include/odb/database.txx:38:5: note: in instantiation of template class 'odb::object_traits_impl, 5>' requested here object_traits::persist (*this, obj); ^ /usr/include/odb/database.ixx:160:12: note: in instantiation of function template specialization 'odb::database::persist_, 5>' requested here return persist_ (obj); ^ main.cpp:25:9: note: in instantiation of function template specialization 'odb::database::persist >' requested here db->persist(S); ^ /usr/include/odb/forward.hxx:99:11: note: template is declared here class object_traits_impl; ^ In file included from main.cpp:11: In file included from /usr/include/odb/sqlite/database.hxx:16: In file included from /usr/include/odb/database.hxx:632: /usr/include/odb/database.txx:38:18: error: incomplete definition of type 'odb::object_traits_impl, 5>' object_traits::persist (*this, obj); ~~~~~~~~~~~~~^~ /usr/include/odb/database.ixx:160:12: note: in instantiation of function template specialization 'odb::database::persist_, 5>' requested here return persist_ (obj); ^ main.cpp:25:9: note: in instantiation of function template specialization 'odb::database::persist >' requested here db->persist(S); ^ In file included from main.cpp:11: In file included from /usr/include/odb/sqlite/database.hxx:16: In file included from /usr/include/odb/database.hxx:632: /usr/include/odb/database.txx:40:29: error: no member named 'reference_cache_traits' in 'odb::object_traits_impl, 5>' typename object_traits::reference_cache_traits::position_type p ( ~~~~~~~~~~~~~~~^ 3 errors generated. Thanks, Balazs From abv150ci at gmail.com Wed Mar 22 09:05:55 2017 From: abv150ci at gmail.com (=?UTF-8?Q?Aar=C3=B3n_Bueno_Villares?=) Date: Wed Mar 22 09:06:48 2017 Subject: [odb-users] Porting ODB to MXE Message-ID: I was trying to compile ODB for my MXE (mingw) installation for cross-compilation (from Ubuntu to Windows), but I had issues with libodb-mysql, because it needs libmysqlclient (I'm only compiling for windows the static versions of the libraries), but the ./configure script tries to find libmysqlclient_r.a and a soft-link doesn't work. To don't repeat myself, here I have left a link with a more detailed explanation: https://github.com/mxe/mxe/issues/1731 Best regards, Aar?n. From pustovalovdmit at gmail.com Wed Mar 22 09:53:10 2017 From: pustovalovdmit at gmail.com (=?UTF-8?B?0J/Rg9GB0YLQvtCy0LDQu9C+0LIg0JTQvNC40YLRgNC40Lk=?=) Date: Wed Mar 22 09:53:33 2017 Subject: [odb-users] odb (2.3.0) with MySQL sql-mode NO_AUTO_VALUE_ON_ZERO Message-ID: Hello! I use MySQl with enabled sql-mode NO_AUTO_VALUE_ON_ZERO, which means that it's not possible to use 0 in INSERT statements for PK column to indicate MySQL that it should automatically assign value for PK. I have persistent object of following definition: #pragma db objectstruct person{ #pragma db id auto uint64_t id_ = 0; std::string first_name_; std::string last_name_;}; And table: CREATE TABLE `person` (`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,`first_name` VARCHAR(50) NOT NULL,`last_name` VARCHAR(50) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 collate=utf8_unicode_ci; I assume that 'id auto' specificator should generate following sql in mapper classes: INSERT INTO person (first_name, last_name) VALUES ("John", "Dohn"); or INSERT INTO person (id, first_name, last_name) VALUES (NULL, "John", "Dohn"); but real sql is: INSERT INTO person (id, first_name, last_name) VALUES (0, "John", "Dohn"); which leads to inserting row with PK value equal to zero and leads to duplicate PK errors, instead of inserting row with autoincremented id. Is there some way to force odb compliter to generate proper SQL-code because I don't want to disable NO_AUTO_VALUE_ON_ZERO? From boris at codesynthesis.com Wed Mar 22 12:39:17 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Mar 22 12:39:26 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Bal?zs, > #pragma db value(ResultFloatSeven) definition > > [...] > > ResultFloatSeven S(Values, Id); > > [...] > > db->persist(S); You cannot persist a value directly, only as part of an object. Please read the documentation. Boris From boris at codesynthesis.com Wed Mar 22 12:44:39 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Mar 22 12:44:48 2017 Subject: [odb-users] Porting ODB to MXE In-Reply-To: References: Message-ID: Hi Aar?n, Aar?n Bueno Villares writes: > I was trying to compile ODB for my MXE (mingw) installation for > cross-compilation (from Ubuntu to Windows), but I had issues with > libodb-mysql, because it needs libmysqlclient (I'm only compiling for > windows the static versions of the libraries), but the ./configure script > tries to find libmysqlclient_r.a and a soft-link doesn't work. Perhaps this would be of help, especially the last section: http://www.codesynthesis.com/products/odb/doc/install-mingw.xhtml Boris From boris at codesynthesis.com Wed Mar 22 12:58:51 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Mar 22 12:59:00 2017 Subject: [odb-users] odb (2.3.0) with MySQL sql-mode NO_AUTO_VALUE_ON_ZERO In-Reply-To: References: Message-ID: Hi, ?????????? ??????? writes: > I use MySQl with enabled sql-mode NO_AUTO_VALUE_ON_ZERO, which means that > it's not possible to use 0 in INSERT statements for PK column to indicate > MySQL that it should automatically assign value for PK. > > Is there some way to force odb compliter to generate proper SQL-code > because I don't want to disable NO_AUTO_VALUE_ON_ZERO? Not at the moment. But we had a similar issue with SQLite which was addressed by allowing NULL values for auto ids. Here is the commit: http://scm.codesynthesis.com/?p=odb/odb.git;a=commit;h=4fd2c107242fe9f8e6ba7ded2a789f4de2ccd040 Perhaps we could do the same for MySQL? Boris From abv150ci at gmail.com Wed Mar 22 16:58:10 2017 From: abv150ci at gmail.com (=?UTF-8?Q?Aar=C3=B3n_Bueno_Villares?=) Date: Wed Mar 22 16:59:03 2017 Subject: [odb-users] Porting ODB to MXE In-Reply-To: References: Message-ID: That didn't help to me. I finally solved it editing the configure script manually and compiling the conftest.cpp samples manually to see what happened, adding the set -o xtrace option to the configure script to track the steps and a lot of stuff that I'm trying to forget as fast as possible. I'm not sure what is the minimial amount of work required to fix it, but I solve it with the following steps if I don't forget anything (sorry for my English): https://github.com/mxe/mxe/issues/1731 On 22 March 2017 at 17:44, Boris Kolpackov wrote: > Hi Aar?n, > > Aar?n Bueno Villares writes: > > > I was trying to compile ODB for my MXE (mingw) installation for > > cross-compilation (from Ubuntu to Windows), but I had issues with > > libodb-mysql, because it needs libmysqlclient (I'm only compiling for > > windows the static versions of the libraries), but the ./configure script > > tries to find libmysqlclient_r.a and a soft-link doesn't work. > > Perhaps this would be of help, especially the last section: > > http://www.codesynthesis.com/products/odb/doc/install-mingw.xhtml > > Boris > From abv150ci at gmail.com Wed Mar 22 17:54:18 2017 From: abv150ci at gmail.com (=?UTF-8?Q?Aar=C3=B3n_Bueno_Villares?=) Date: Wed Mar 22 17:55:10 2017 Subject: [odb-users] Porting ODB to MXE In-Reply-To: References: Message-ID: I get linking errors when compiling my app. On 22 March 2017 at 21:58, Aar?n Bueno Villares wrote: > That didn't help to me. > > I finally solved it editing the configure script manually and compiling > the conftest.cpp samples manually to see what happened, adding the set -o > xtrace option to the configure script to track the steps and a lot of stuff > that I'm trying to forget as fast as possible. > > I'm not sure what is the minimial amount of work required to fix it, but I > solve it with the following steps if I don't forget anything (sorry for my > English): > > https://github.com/mxe/mxe/issues/1731 > > On 22 March 2017 at 17:44, Boris Kolpackov > wrote: > >> Hi Aar?n, >> >> Aar?n Bueno Villares writes: >> >> > I was trying to compile ODB for my MXE (mingw) installation for >> > cross-compilation (from Ubuntu to Windows), but I had issues with >> > libodb-mysql, because it needs libmysqlclient (I'm only compiling for >> > windows the static versions of the libraries), but the ./configure >> script >> > tries to find libmysqlclient_r.a and a soft-link doesn't work. >> >> Perhaps this would be of help, especially the last section: >> >> http://www.codesynthesis.com/products/odb/doc/install-mingw.xhtml >> >> Boris >> > > From obermann.lukas at gmail.com Thu Mar 23 04:25:40 2017 From: obermann.lukas at gmail.com (Lukas Obermann) Date: Thu Mar 23 04:25:55 2017 Subject: [odb-users] Subselects in View In-Reply-To: References: Message-ID: <05A064D9-465F-4082-AA37-BCBA026229D3@gmail.com> Hi Boris, thank you for the help! I think I mixed that up a bit. With ?complex? I meant building queries on-the-fly without the use of views, that use joins ans subselects. I have two more questions regarding the native view. How to handle if the relation from table2 to table2 is done via a lazy_shared_ptr? And, can I also reference it when the relation is done via a vector, thus having a separate table in between them. Thanks, Lukas > Am 20.03.2017 um 17:21 schrieb Boris Kolpackov : > > Hi Lukas, > > Lukas Obermann writes: > >> I know that it is not recommended to do complex queries with odb, [...] > > Not recommended by whom? > > You can handle pretty much any query with an ODB native view. It may not > be as convenient as for simpler queries, but it is definitely possible > and not "not recommended". > > >> SELECT table1.name, (SELECT AVG(score) FROM table2 WHERE >> table2.t_id = table1.t_id) as score FROM table1 > > You can handle it pretty easily with a native view. You can even get fancy > and do something like this: > > #include > > #pragma db object > struct table1 > { > #pragma db id > int t_id; > > std::string name; > }; > > #pragma db object > struct table2 > { > #pragma db id > int t_id; > > int score; > }; > > #pragma db view object(table1) object(table2) \ > query("SELECT " + table1::name + ", " \ > "(" \ > " SELECT AVG(" + table2::score + ")" \ > " FROM " + (object_traits_impl::table_name) + \ > " WHERE " + (table2::t_id == table1::t_id) + \ > ") AS score" \ > "FROM " + (object_traits_impl::table_name)) > struct view > { > std::string name; > int avg_score; > }; > > You can read moe about table_name here: > > [1] http://www.codesynthesis.com/pipermail/odb-users/2016-April/003209.html > > Boris From pustovalovdmit at gmail.com Thu Mar 23 11:05:11 2017 From: pustovalovdmit at gmail.com (=?UTF-8?B?0J/Rg9GB0YLQvtCy0LDQu9C+0LIg0JTQvNC40YLRgNC40Lk=?=) Date: Thu Mar 23 11:05:35 2017 Subject: [odb-users] odb (2.3.0) with MySQL sql-mode NO_AUTO_VALUE_ON_ZERO In-Reply-To: References: Message-ID: Thx, Boris. This approach works. ??, 22 ???. 2017 ?. ? 19:58, Boris Kolpackov : > Hi, > > ?????????? ??????? writes: > > > I use MySQl with enabled sql-mode NO_AUTO_VALUE_ON_ZERO, which means that > > it's not possible to use 0 in INSERT statements for PK column to indicate > > MySQL that it should automatically assign value for PK. > > > > Is there some way to force odb compliter to generate proper SQL-code > > because I don't want to disable NO_AUTO_VALUE_ON_ZERO? > > Not at the moment. But we had a similar issue with SQLite which was > addressed by allowing NULL values for auto ids. Here is the commit: > > > http://scm.codesynthesis.com/?p=odb/odb.git;a=commit;h=4fd2c107242fe9f8e6ba7ded2a789f4de2ccd040 > > Perhaps we could do the same for MySQL? > > Boris > From Wolfgang.Neuner at swarovski.com Fri Mar 24 02:19:35 2017 From: Wolfgang.Neuner at swarovski.com (Neuner Wolfgang) Date: Fri Mar 24 02:20:04 2017 Subject: [odb-users] 'lazy_weak_ptr' is not a member of 'odb' Message-ID: i try to use the lazy pointers as described in 6.4. But i get the following odb compile error: clib.hxx:40:14: error: 'lazy_weak_ptr' is not a member of 'odb' std::vector > m_ClibRights; ^ clib.hxx:40:14: error: 'lazy_weak_ptr' is not a member of 'odb' clib.hxx:40:46: error: template argument 1 is invalid std::vector > m_ClibRights; ^ clib.hxx:40:46: error: template argument 2 is invalid clib.hxx:40:48: error: expected unqualified-id before '>' token std::vector > m_ClibRights; ^ clib.hxx:52:7: error: 'lazy_shared_ptr' in namespace 'odb' does not name a template type odb::lazy_shared_ptr m_AuthMandant; I included the lazy-ptr header, but the odb compiler cannot find the definition of the lazy pointers. Where is the problem? My odb command line: odb.exe -I C:\Data\Entwicklung\APIs\libodb-2.4.0\ --database mysql --generate-query --generate-schema clib.hxx My clib.hxx: #include class COdbClibRight; #pragma db object table("auth_mandant") class COdbAuthMandant { public: COdbAuthMandant() {}; int GetId() const { return m_iId; }; const std::string& GetName() const { return m_sName; }; void SetName(std::string& name){ m_sName = name; }; const std::string& GetAddress() const { return m_sAddress; }; void SetAddress(std::string& address) { m_sAddress = address; }; private: #pragma db member id auto column("id") get(GetId) int m_iId; #pragma db member column("name") get(GetName) set(SetName) type("VARCHAR(50)") std::string m_sName; #pragma db member column("address") get(GetAddress) set(SetAddress) type("VARCHAR(250)") std::string m_sAddress; #pragma db member column("contact") get(GetContact) set(SetContact) type("VARCHAR(250)") std::string m_sContact; #pragma db member column("factory") get(GetFactory) set(SetFactory) type("VARCHAR(50)") std::string m_sFactory; #pragma db value_not_null inverse(m_AuthMandant) std::vector > m_ClibRights; }; #pragma db object table("clib_right") class COdbClibRight { public: COdbClibRight() {}; private: #pragma db not_null odb::lazy_shared_ptr m_AuthMandant; }; From boris at codesynthesis.com Fri Mar 24 05:58:01 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Mar 24 05:58:09 2017 Subject: [odb-users] 'lazy_weak_ptr' is not a member of 'odb' In-Reply-To: References: Message-ID: Hi Wolfgang, Neuner Wolfgang writes: > clib.hxx:40:14: error: 'lazy_weak_ptr' is not a member of 'odb' > std::vector > m_ClibRights; > > > odb.exe -I C:\Data\Entwicklung\APIs\libodb-2.4.0\ --database mysql > --generate-query --generate-schema clib.hxx odb::lazy_weak_ptr corresponds to std::lazy_ptr which is only available since C++11. So you need to run the ODB compiler in the C++11 mode (--std c++11). Boris From marco.craveiro at gmail.com Sat Mar 25 15:43:24 2017 From: marco.craveiro at gmail.com (Marco Craveiro) Date: Sat Mar 25 15:43:38 2017 Subject: [odb-users] Using prefetch with Oracle In-Reply-To: References: <20170213135652.GA22900@codesynthesis.com> Message-ID: Hi Boris, Ok at long last I've finished my series of posts ([1], [2]); I can now reproduce the problems I was having in production locally, so I can finally start working on the ODB patch. > Good stuff. I need to setup an Oracle 11 VM soon. Now I know which guide > I will use ;-). Actually, if you just want to build a Linux Oracle 11 VM, you don't need to read all of that stuff :-) my recommendations: 1. Use a RPM based distribution such as CentOS or Fedora. This will greatly simplify your life (the articles explain how to install the RPMs on Debian). 2. Install just the Oracle Express package as per part I [3]. You need that one package - I was confused and downloaded lots of other packages, but actually you don't need to do all of that. 3. Run the oracle env script to ensure you have all of the directories in the path, and set your includes and libs accordingly. It will also place SQL Plus on the path. That's pretty much it. Any problems let me know as it's still fresh in my mind, so I may be able to help. Cheers -- Marco Craveiro MD, Domain Driven Consulting about: http://about.me/marcocraveiro blog: http://mcraveiro.blogspot.co.uk twitter: https://twitter.com/MarcoCraveiro That the Ideas are themselves manifestations (of the Idea-Idea) and that the Idea-Idea is a-kind-of Manifestation-Idea?which is a-kind-of itself, so that the system is completely self-describing? would have been appreciated by Plato as an extremely practical joke [Plato]. -- Alan Key [1] http://mcraveiro.blogspot.co.uk/2017/03/nerd-food-northwind-or-using-dogen-with.html [2] http://mcraveiro.blogspot.co.uk/2017/03/nerd-food-northwind-or-using-dogen-with_25.html [3] http://mcraveiro.blogspot.co.uk/2017/02/nerd-food-northwind-or-using-dogen-with.html From balazs.bayer at gmail.com Fri Mar 24 18:27:22 2017 From: balazs.bayer at gmail.com (=?UTF-8?Q?Bal=C3=A1zs_Bayer?=) Date: Mon Mar 27 09:19:07 2017 Subject: [odb-users] Persisting class instantiated from a template In-Reply-To: References: Message-ID: Hi Boris, with #pragma db object(ResultFloatSeven) definition #pragma db member(ResultFloatSeven::Id) id it is ok now. Many thanks for your help, and best regards, Bal?zs On 22 March 2017 at 17:39, Boris Kolpackov wrote: > Hi Bal?zs, > > > #pragma db value(ResultFloatSeven) definition > > > > [...] > > > > ResultFloatSeven S(Values, Id); > > > > [...] > > > > db->persist(S); > > You cannot persist a value directly, only as part of an object. Please > read the documentation. > > Boris > From fanz at linux.com Mon Mar 27 15:24:04 2017 From: fanz at linux.com (Fan Zhang) Date: Mon Mar 27 15:24:17 2017 Subject: [odb-users] best practice to access query result across transaction Message-ID: Hi, guys, First post here. I learned from here (http://www.codesynthesis.com/pipermail/odb-users/2015-July/002682.html ) that the query result can not be accessed after the transaction is ended. I?m therefore copying stuff to a vector, which can be expensive. I guess odb must have some built-in support for this. Could you shed some light? Thanks, Fan From boris at codesynthesis.com Tue Mar 28 10:12:29 2017 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Mar 28 10:12:38 2017 Subject: [odb-users] best practice to access query result across transaction In-Reply-To: References: Message-ID: Hi Fan, Fan Zhang writes: > [...] that the query result can not be accessed after the transaction > is ended. I?m therefore copying stuff to a vector, which can be expensive. > I guess odb must have some built-in support for this. The reason you cannot access the query result after the transaction is because most databases stream the data as you iterate over it. Given this understanding, I wonder what kind of "magic" you expect ODB to provide here? Boris From fanz at linux.com Tue Mar 28 10:35:27 2017 From: fanz at linux.com (Fan Zhang) Date: Tue Mar 28 10:35:39 2017 Subject: [odb-users] best practice to access query result across transaction In-Reply-To: References: Message-ID: <04BF5FA6-5795-4D58-9F4F-C2DE0471A831@linux.com> I see. Just want to double check. Then I?ll just copy it. Fan > On Mar 28, 2017, at 10:12 AM, Boris Kolpackov wrote: > > Hi Fan, > > Fan Zhang writes: > >> [...] that the query result can not be accessed after the transaction >> is ended. I?m therefore copying stuff to a vector, which can be expensive. >> I guess odb must have some built-in support for this. > > The reason you cannot access the query result after the transaction is > because most databases stream the data as you iterate over it. Given > this understanding, I wonder what kind of "magic" you expect ODB to > provide here? > > Boris