From boris at codesynthesis.com Mon Jul 1 09:57:22 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 1 09:57:08 2024 Subject: [odb-users] make integer field autoincrement when it wasn't In-Reply-To: References: Message-ID: MM writes: > But when I add it, odb errors with: > "error: changing object id auto kind in an existing class is not supported > info: consider re-implementing this change by adding a new class with the > desired object id auto kind, migrating the data, and deleting the old class" Right, there is no way to do this migration automatically (i.e., there is no ALTER COLUMN ... ADD AUTOINCREMENET or some such). > Can I manually hack around this? ie I edit the old xmls? and then edit the > database myself? Yes, you can, provided you don't expect the automatic migration from databases without auto to work magically somehow. From finjulhich at gmail.com Mon Jul 1 14:45:20 2024 From: finjulhich at gmail.com (MM) Date: Mon Jul 1 14:45:50 2024 Subject: [odb-users] make integer field autoincrement when it wasn't Message-ID: On Mon, 1 Jul 2024 at 14:57, Boris Kolpackov wrote: > MM writes: > > > But when I add it, odb errors with: > > "error: changing object id auto kind in an existing class is not > supported > > info: consider re-implementing this change by adding a new class with the > > desired object id auto kind, migrating the data, and deleting the old > class" > > Right, there is no way to do this migration automatically (i.e., there > is no ALTER COLUMN ... ADD AUTOINCREMENET or some such). > > > > Can I manually hack around this? ie I edit the old xmls? and then edit > the > > database myself? > > Yes, you can, provided you don't expect the automatic migration from > databases without auto to work magically somehow. Yes, that's fine. But when I add *auto *to the odb pragma, the odb compiler doesn't let me progress. There's the use of existing xml files I think for schema evolution. what steps do I follow to hack this in? 1. edit the xml 2. add auto to the #pragma id 3. run odb? 4. update the sql database manually? is this the right order? MM From boris at codesynthesis.com Tue Jul 2 08:55:46 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Jul 2 08:55:31 2024 Subject: [odb-users] Mutex may not be released Re: It was blocked by odb::sqlite::connection_pool_factory::create() In-Reply-To: <3AEBBBF8-8875-45F9-83B8-7A909E000708@ringcentral.com> References: <3AEBBBF8-8875-45F9-83B8-7A909E000708@ringcentral.com> Message-ID: Sunny Sun writes: > Yes, we really got win32_exception() when call odb::sqlite::connection(). > > [...] > > The above code throw win32_exception(), but not sure which line throw it. > We got 2 times win32_exception(). > > [...] > > This issue only happened once, and we did not find out the root cause. > > We only find this issue same began with the win32_exception(). It's hard to know what could be causing this without at least knowing where the exception is thrown. I looked at all the throw sites and all of them related to the Win32 thread synchronization primitives so it is very strange. One thing you can try is to update to the latest 2.5.0 pre-release (which is currently at the release candidate stage). In 2.5.0 we have switched to C++11 threading API so maybe that will help. For instructions on how to build ODB 2.5.0, see: https://codesynthesis.com/products/odb/doc/install-build2.xhtml The latest status update for this release is here: https://codesynthesis.com/pipermail/odb-users/2024-June/005009.html From finjulhich at gmail.com Sat Jul 6 11:16:03 2024 From: finjulhich at gmail.com (MM) Date: Sat Jul 6 11:16:34 2024 Subject: [odb-users] Update and persist all objects of a query result Message-ID: Hello, The result iterator being a input iterator, I suspect this loop is incorrect: odb::result result = db.query(....); for( auto& obj: result ) { obj.myfield = ""; db.update(obj); } Am I right? I think the above SEGV What is the correct way of storing empty strings for a group of objects? From uwe.kindler at cetoni.de Tue Jul 9 02:21:47 2024 From: uwe.kindler at cetoni.de (CETONI GmbH - Uwe Kindler) Date: Tue Jul 9 06:01:45 2024 Subject: [odb-users] MSVC19 link error: LNK2001: Unresolved external symbol In-Reply-To: References: <344ee50b-56e7-4e53-954c-4f84443422e1@cetoni.de> Message-ID: <3f33aa5e-9076-46d2-b212-a4403898da96@cetoni.de> > CETONI GmbH - Uwe Kindler writes: > >> error LNK2001: Unresolved external symbol ""struct odb::details::share >> odb::details::shared" (?shared@details@odb@@3Ushare@12@A)" >> >> The symbol is declared in odb/details/shared_ptr/base.hxx: >> >> >> extern LIBODB_EXPORT share shared; > I believe adding -DLIBODB_SHARED to your MSVC compiler command line > when building your application (and generated code) will help. > > For background, without either LIBODB_SHARED or LIBODB_STATIC we > fall back to automatic symbol importing but in MSVC it only works > for functions, not global variables (this is the reason why you > only see this unresolved symbol rather than many -- the rest are > all functions and that works). Thank you very much - this solved the issue. From uwe.kindler at cetoni.de Tue Jul 9 05:02:27 2024 From: uwe.kindler at cetoni.de (CETONI GmbH - Uwe Kindler) Date: Tue Jul 9 06:01:45 2024 Subject: [odb-users] MSVC19 Linker error when deriving from an ORM object in another DLL Message-ID: <9f048546-b077-44cc-99a2-232506be9a34@cetoni.de> Hi, We are switching from MinGW compiler to MSVC19 compiler and see linker errors, when deriving an ORM object from an ORM object in a different DLL. The first DLL *qtlabb_items.dl*l contains the following ORM objects: PositionableItem.h #pragmadb model version(1, 1) #pragmadb object abstract classQTLABB_ITEMS_EXPORTCPositionableItem { private: friendclassodb::access;///< allow ODB ORM to access out private members #pragmadb id auto longm_Id; #pragmadb transient CPositionableItem* m_Parent;///< points to parent container (0 if no parent) doublem_CenterX; doublem_CenterY; doublem_CenterZ; doublem_Rotation; #pragmadb transient mutableQtLabb::CTransformm_Transform;///< transformation matrix #pragmadb transient mutableDatabase::COdbSqliteDatabase* m_Database;///< reference to the database where this item is stored Container.h #pragmadb object abstract classQTLABB_ITEMS_EXPORTCContainer: publicCPositionableItem { protected: friendclassodb::access;///< allow ODB ORM to access to private members doublem_SizeX;///< length of this container doublem_SizeY;///< width of this container doublem_Height;///< the height of this container QStringm_Name;///< the container name unsignedintm_ColorARGB; ///< color of this well plate RowColumnContainer.h /** * A CRowColumnContainer is an abstraction of a container that has a number of * equal child containers arranged in rows and columns. * I.e. a well plate is a kind of CRowColumnContainer */ #pragmadb model version(1, 1) #pragmadb object abstract classQTLABB_ITEMS_EXPORTCRowColumnContainer: publicCContainer { protected: friendclassodb::access;///< allow ODB ORM to access to private members intm_RowCount;///< number of cavity rows of this container doublem_RowSpacing;///< row spacing - the space between centers of two cavities intm_ColumnCount;///< number of cavity columns of this container doublem_ColumnSpacing;///< column spacing RowColumnContainer.h (derived from CContainer) The second DLL *qtlabb_fluidhandling.dll* containes the following ORM object PipetteStore.h (derived from CRowColumnContainer): #pragmadb model version(1, 1) #pragmadb object classQTLABB_FLUIDHANDLING_EXPORTCPipetteStore: publicCRowColumnContainer { private: friendclassodb::access;///< allow ODB ORM to access to private members /** * Default constructor for ORM */ CPipetteStore(); /** * Private constructor called from public constructors */ voidprivConstructor(CPipetteStoreParamsconst* Params = 0); protected: #pragmadb transient PipetteStorePrivate* d;///< private transient data of pipettestore QVector m_SlotFilledStates;///< for ORM filled state of all slots When compiling the qtlabb_fluidhandling.dll, we see a number of linker errors in the PipetteStore-odb.obj file compiled from PipetteStore-odb.cpp generated from ODB compiler: PipetteStore-odb.obj : error LNK2019: Verweis auf nicht aufgel?stes externes Symbol ""public: static long __cdecl odb::access::object_traits_impl::id(struct odb::access::object_traits_impl::id_image_type const &)" (?id@?$object_traits_impl@VCPositionableItem@QtLabb@@$00@access@odb@@SAJAEBUid_image_type@123@@Z)" in Funktion ""public: static long __cdecl odb::access::object_traits_impl::id(struct odb::access::object_traits_impl::id_image_type const &)" (?id@?$object_traits_impl@VCPipetteStore@QtLabb@@$00@access@odb@@SAJAEBUid_image_type@?$object_traits_impl@VCPositionableItem@QtLabb@@$00@23@@Z)". I can solve this issue by manually adding QTLABB_ITEMS_EXPORT macros to the static class members but I'm not sure, if it is the right way to manually add export macros to a generated file. What is the right way to properly export the data generated by ORM compiler. Thank you, Uwe From becoggins at hotmail.com Wed Jul 10 23:42:30 2024 From: becoggins at hotmail.com (Brian Coggins) Date: Wed Jul 10 23:42:54 2024 Subject: [odb-users] WITH Queries in Views Message-ID: Hello Boris and friends, Back in Jan 2023, I was running into trouble trying to create a view using a WITH ? query, and Boris helpfully explained about the ODB compiler: Yes, it tries to guess whether it's a complete query or the WHERE clause by checking if the query starts with one of the known keywords (like SELECT). I have a TODO item to recognize some additional database- specific keywords (like WITH). I?ve run into this limitation again, this time in the context of a WITH RECURSIVE ? query that I don?t think can be accomplished any other way. I upgraded to ODB 2.5.0-b.27 but it seems the issue is still there. Any chance we might be able to get a patch to loosen up these restrictions? Thanks, Brian From boris at codesynthesis.com Tue Jul 9 10:31:44 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 15 12:19:45 2024 Subject: [odb-users] MSVC19 Linker error when deriving from an ORM object in another DLL In-Reply-To: <9f048546-b077-44cc-99a2-232506be9a34@cetoni.de> References: <9f048546-b077-44cc-99a2-232506be9a34@cetoni.de> Message-ID: CETONI GmbH - Uwe Kindler writes: > What is the right way to properly export the data generated by ORM compiler. Have you tried the --export-symbol ODB compiler option? https://www.codesynthesis.com/products/odb/doc/odb.xhtml For some examples, see also: https://www.codesynthesis.com/products/odb/doc/manual.xhtml#16.2.2 From uwe.kindler at cetoni.de Wed Jul 17 02:21:42 2024 From: uwe.kindler at cetoni.de (CETONI GmbH - Uwe Kindler) Date: Thu Jul 18 10:45:53 2024 Subject: [odb-users] MSVC19 Linker error when deriving from an ORM object in another DLL In-Reply-To: References: <9f048546-b077-44cc-99a2-232506be9a34@cetoni.de> Message-ID: > CETONI GmbH - Uwe Kindler writes: > >> What is the right way to properly export the data generated by ORM compiler. > Have you tried the --export-symbol ODB compiler option? > > https://www.codesynthesis.com/products/odb/doc/odb.xhtml > > For some examples, see also: > > https://www.codesynthesis.com/products/odb/doc/manual.xhtml#16.2.2 Thank you Boris - this works perfecly fine and was the right solution. I've been using MinGW until today, so this hasn't been a problem so far - that's why I missed this documentation part completely. Sorry, I have to RTFM :o) From finjulhich at gmail.com Sun Jul 21 15:58:28 2024 From: finjulhich at gmail.com (MM) Date: Sun Jul 21 15:58:59 2024 Subject: [odb-users] querying object and loading into a stack variable, then setting its id to 0 and persisting Message-ID: Hi, struct C { std::uint64_t id; #pragma member id auto .... }; C myc; db.query_one(..., myc); /// successful myc.setid(0); myc.changeotherattributes(); db.persist(myc); /// this seems to INSERT a new object with value 0 for id, but my intention is to clone the loaded object myc, change attributes, and let the database determine the new id. do I just get a copy of myc then work on that instead? does odb keep track of the object memory addresses for determining whether to UPDATE vs INSERT? confused, From boris at codesynthesis.com Mon Jul 22 00:52:00 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 22 00:52:12 2024 Subject: [odb-users] querying object and loading into a stack variable, then setting its id to 0 and persisting In-Reply-To: References: Message-ID: MM writes: > struct C { > std::uint64_t id; #pragma member id auto > .... > }; > > C myc; > db.query_one(..., myc); > /// successful > myc.setid(0); > myc.changeotherattributes(); > > db.persist(myc); > > /// this seems to INSERT a new object with value 0 for id, but my intention > is to clone the loaded object myc, change attributes, and let the database > determine the new id. Provided the C::id member is auto-assigned, this should do what you expect so I suspect there is something wrong with your setup. If you think this is a bug in ODB, please provide a complete reproducer and also specify which database we are talking about. In fact, ALWAYS specify which database we are talking about. > does odb keep track of the object memory addresses for determining whether > to UPDATE vs INSERT? No, ODB doesn't do anything like this. From finjulhich at gmail.com Mon Jul 22 02:32:37 2024 From: finjulhich at gmail.com (MM) Date: Mon Jul 22 02:33:09 2024 Subject: [odb-users] querying object and loading into a stack variable, then setting its id to 0 and persisting Message-ID: On Mon, 22 Jul 2024 at 05:52, Boris Kolpackov wrote: > MM writes: > > > struct C { > > std::uint64_t id; #pragma member id auto > > .... > > }; > > > > C myc; > > db.query_one(..., myc); > > /// successful > > myc.setid(0); > > myc.changeotherattributes(); > > > > db.persist(myc); > > > > /// this seems to INSERT a new object with value 0 for id, but my > intention > > is to clone the loaded object myc, change attributes, and let the > database > > determine the new id. > > Provided the C::id member is auto-assigned, this should do what you expect > so I suspect there is something wrong with your setup. If you think this is > a bug in ODB, please provide a complete reproducer and also specify which > database we are talking about. In fact, ALWAYS specify which database we > are talking about. > > > > does odb keep track of the object memory addresses for determining > whether > > to UPDATE vs INSERT? > > No, ODB doesn't do anything like this. This is sqlite. The stderr tracer shows a INSERT statement like so: INSERT INTO "C" ("id", "attr1", "attr2") VALUES (?, ?, ?,) I am confused as to why "id" is in the INSERT statement, given that it is auto The changelog.xml has this section for table C The CREATE TABLE in sqlite has PRIMARY KEY("id" AUTOINCREMENT), I don't think it's a odb bug. The full picture is struct Base { std::uint64_t id; #pragma member(Base::id) id auto virtual(std::uint64_t) }; template class cloneable : public base { protected: using base::base; virtual base* clone() const override { return new derived{static_cast(*this)}; } }; struct C : public cloneable { ... }; /// order of inclusion matters otherwise odb compiler crashes struct C; using derived_C = cloneable; #pragma db object(derived_C) abstract definition Does the fact that the id come from the base struct cause a problem, is it because it's virtual in Base it doesn't auto increment? Thanks From boris at codesynthesis.com Tue Jul 23 00:54:29 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Jul 23 04:43:31 2024 Subject: [odb-users] querying object and loading into a stack variable, then setting its id to 0 and persisting In-Reply-To: References: Message-ID: MM writes: > The full picture is > > struct Base { > std::uint64_t id; #pragma member(Base::id) id auto > virtual(std::uint64_t) > }; I am not sure about being full, but I am pretty sure it's not an accurate picture. If I try to compile the above code fragment as-is (after removing the line break between `auto` and `virtual` which I assume was added by your email client), so this: struct Base { std::uint64_t id; #pragma member(Base::id) id auto virtual(std::uint64_t) }; I get: test.hxx:2:23: error: stray ?#? in program Please send a complete, compilable reproducer if you want me to look into this further. From sunny.sun at ringcentral.com Thu Jul 25 05:04:40 2024 From: sunny.sun at ringcentral.com (Sunny Sun) Date: Sat Jul 27 06:06:01 2024 Subject: [odb-users] Mutex may not be released Re: It was blocked by odb::sqlite::connection_pool_factory::create() In-Reply-To: References: <3AEBBBF8-8875-45F9-83B8-7A909E000708@ringcentral.com> Message-ID: Hi?a bad news is the same issue happened again(odb 2.4). I downloaded the source code here: https://git.codesynthesis.com/cgit/odb/odb/ and tried to understand? In 2.5.0 we have switched to C++11 threading API so maybe that will help. But from the code I didn?t find out the exact change. What apis/interfaces does odb switched? Also, we found that once a win32 error is caught, subsequent attempts to create a connection will be blocked. There may be some causal relationship. Could you help analyze it? Thank you in advance. On Jul 2, 2024, at 20:55, Boris Kolpackov wrote: [EXTERNAL] Sunny Sun writes: Yes, we really got win32_exception() when call odb::sqlite::connection(). [...] The above code throw win32_exception(), but not sure which line throw it. We got 2 times win32_exception(). [...] This issue only happened once, and we did not find out the root cause. We only find this issue same began with the win32_exception(). It's hard to know what could be causing this without at least knowing where the exception is thrown. I looked at all the throw sites and all of them related to the Win32 thread synchronization primitives so it is very strange. One thing you can try is to update to the latest 2.5.0 pre-release (which is currently at the release candidate stage). In 2.5.0 we have switched to C++11 threading API so maybe that will help. For instructions on how to build ODB 2.5.0, see: https://urldefense.com/v3/__https://codesynthesis.com/products/odb/doc/install-build2.xhtml__;!!J-1DKIBqn-Pi!CBzDrRJmfUVqDFgoq0eBZiTxdmFt_Vcd-u9IPaxRRiHVrPPPWI76WWj2sds0sTtPkPjNvWGISba3n2uEtK_Q1A$ The latest status update for this release is here: https://urldefense.com/v3/__https://codesynthesis.com/pipermail/odb-users/2024-June/005009.html__;!!J-1DKIBqn-Pi!CBzDrRJmfUVqDFgoq0eBZiTxdmFt_Vcd-u9IPaxRRiHVrPPPWI76WWj2sds0sTtPkPjNvWGISba3n2vwnoy1xg$ From Matthias.Seiler at stadlerrail.com Thu Jul 25 07:19:30 2024 From: Matthias.Seiler at stadlerrail.com (Seiler Matthias SIGCH) Date: Sat Jul 27 06:07:23 2024 Subject: [odb-users] Cannot find Boost header file Message-ID: <078639b53a734dcea06e2270caf896ac@stadlerrail.com> Hi Boris, I'd like to include the runtime library for Boost, however, when I enable the profile, it throws the following: 1>C:\odb\debug\include/odb/boost/date-time/mssql/gregorian-mapping.hxx:7:10: fatal error: boost/date_time/gregorian/gregorian_types.hpp: No such file or directory 1> 7 | #include 1> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I call ODB like this: odb -v -I C:\odb\debug\include --std c++14 --profile boost -d mssql --generate-query --output-dir generated --generate-schema --schema-format embedded Tables\*.hxx I also added the path to boost (i.e. -I "C:\Program Files\boost\boost_1_85_0\boost"), which results in the same error. The ODB version is 2.5.0-b.27, build with build2 v0.17.0 [1] and Boost's version is 1.85.0 You can find the full build output here [2]. Can you help me solving this issue? Cheers, Matthias [1] https://www.codesynthesis.com/products/odb/doc/install-build2.xhtml#windows [2] https://rentry.co/odb-boost-profile From boris at codesynthesis.com Mon Jul 29 09:21:19 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 29 09:20:58 2024 Subject: [odb-users] Mutex may not be released Re: It was blocked by odb::sqlite::connection_pool_factory::create() In-Reply-To: References: <3AEBBBF8-8875-45F9-83B8-7A909E000708@ringcentral.com> Message-ID: Sunny Sun writes: > I downloaded the source code here: https://git.codesynthesis.com/cgit/odb/odb/ and tried to understand? > > > In 2.5.0 we have switched to C++11 threading API so maybe that will help. > > But from the code I didn?t find out the exact change. What apis/interfaces > does odb switched? The Win32-based support is still in 2.5.0 and is unchanged (it will be dropped in 2.6.0 once we drop support for C++98/03). But by default in 2.5.0 we don't use it, instead using the C++11 threading support. This is controlled with the ODB_THREADS_* macros, for example: https://git.codesynthesis.com/cgit/odb/libodb/tree/odb/details/mutex.hxx > Could you help analyze it? I will again suggest that you try 2.5.0 and see if that makes a difference. From boris at codesynthesis.com Mon Jul 29 09:23:47 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 29 09:23:24 2024 Subject: [odb-users] Cannot find Boost header file In-Reply-To: <078639b53a734dcea06e2270caf896ac@stadlerrail.com> References: <078639b53a734dcea06e2270caf896ac@stadlerrail.com> Message-ID: Seiler Matthias SIGCH writes: > 1>C:\odb\debug\include/odb/boost/date-time/mssql/gregorian-mapping.hxx:7:10: fatal error: boost/date_time/gregorian/gregorian_types.hpp: No such file or directory > 1> 7 | #include > 1> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > I also added the path to boost (i.e. > -I "C:\Program Files\boost\boost_1_85_0\boost"), which results in the > same error. Try adding -I "C:\Program Files\boost\boost_1_85_0" instead (as can be seen from the above error, the Boost headers are included with the boost/ prefix). From Matthias.Seiler at stadlerrail.com Tue Jul 30 02:29:01 2024 From: Matthias.Seiler at stadlerrail.com (Seiler Matthias SIGCH) Date: Tue Jul 30 05:34:30 2024 Subject: AW: [EXTERNAL]Re: [odb-users] Cannot find Boost header file In-Reply-To: References: <078639b53a734dcea06e2270caf896ac@stadlerrail.com> Message-ID: <5048d7df332c43a89a4da9c9b5226d4c@stadlerrail.com> Thanks for your help! Unfortunately, it now seems not to find odb headers: 1>C:\gitlab\ProjectName\generated\Table-odb.cxx(7,10): error C1083: Cannot open include file: 'odb/pre.hxx': No such file or directory 1>C:\gitlab\ProjectName\ProjectClass.h(5,10): error C1083: Cannot open include file: 'odb/database.hxx': No such file or directory -----Urspr?ngliche Nachricht----- Von: Boris Kolpackov Gesendet: Montag, 29. Juli 2024 15:24 An: Seiler Matthias SIGCH Cc: odb-users@codesynthesis.com Betreff: [EXTERNAL]Re: [odb-users] Cannot find Boost header file Seiler Matthias SIGCH writes: > 1>C:\odb\debug\include/odb/boost/date-time/mssql/gregorian-mapping.hxx:7:10: fatal error: boost/date_time/gregorian/gregorian_types.hpp: No such file or directory > 1> 7 | #include > 1> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > I also added the path to boost (i.e. > -I "C:\Program Files\boost\boost_1_85_0\boost"), which results in the > same error. Try adding -I "C:\Program Files\boost\boost_1_85_0" instead (as can be seen from the above error, the Boost headers are included with the boost/ prefix). From boris at codesynthesis.com Tue Jul 30 05:47:59 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Jul 30 05:47:39 2024 Subject: [EXTERNAL]Re: [odb-users] Cannot find Boost header file In-Reply-To: <5048d7df332c43a89a4da9c9b5226d4c@stadlerrail.com> References: <078639b53a734dcea06e2270caf896ac@stadlerrail.com> <5048d7df332c43a89a4da9c9b5226d4c@stadlerrail.com> Message-ID: Seiler Matthias SIGCH writes: > Unfortunately, it now seems not to find odb headers: > > 1>C:\gitlab\ProjectName\generated\Table-odb.cxx(7,10): error C1083: Cannot open include file: 'odb/pre.hxx': No such file or directory > 1>C:\gitlab\ProjectName\ProjectClass.h(5,10): error C1083: Cannot open include file: 'odb/database.hxx': No such file or directory Well, this is no longer the ODB compiler, but rather you compiling the generated code with your C++ compiler, right? In this case, try adding -I C:\odb\debug\include . From finjulhich at gmail.com Wed Jul 31 04:20:44 2024 From: finjulhich at gmail.com (MM) Date: Wed Jul 31 04:21:16 2024 Subject: [odb-users] querying object and loading into a stack variable, then setting its id to 0 and persisting Message-ID: >> The full picture is >> >> struct Base { >> std::uint64_t id; #pragma member(Base::id) id auto >> virtual(std::uint64_t) >> }; >I am not sure about being full, but I am pretty sure it's not an >accurate picture. If I try to compile the above code fragment as-is >(after removing the line break between `auto` and `virtual` which I> assume was added by your email client), so this: >struct Base { > std::uint64_t id; #pragma member(Base::id) id auto virtual(std::uint64_t) >}; >I get: >test.hxx:2:23: error: stray ?#? in program >Please send a complete, compilable reproducer if you want me to look >into this further. Hello This standalone file compiles for me with gcc #include #include typedef std::uint64_t Baseid_t; struct Base { void set_id(Baseid_t); Baseid_t get_id() const; virtual Base* clone() const =0; virtual ~Base() =default; protected: Base(); Baseid_t id_; /// obtained from database }; #pragma db object(Base) abstract definition transient #pragma db member(Base::id) id auto virtual(Baseid_t) template class cloneable : public tbase { protected: using tbase::tbase; virtual tbase* clone() const override { return new derived{static_cast(*this)}; } }; struct Derived; using derived_Derived_ctrct = cloneable; #pragma db object(derived_Derived_ctrct) abstract definition struct Derived : public cloneable { double data1; }; #pragma db object(Derived) table("Deriveds") definition int main() { return 0; } Let me know if I should add to this code for opening a database and for calling the persist() method, where the tracer shows that the INSERT INTO query still uses the 'id' column? >From a first look as to how I wrote the Base::id member pragma, do you think the generated SQL stmt should not use column id because the database will take care of that? From boris at codesynthesis.com Wed Jul 31 09:17:21 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 31 09:16:58 2024 Subject: [odb-users] WITH Queries in Views In-Reply-To: References: Message-ID: Brian Coggins writes: > Yes, it tries to guess whether it's a complete query or the WHERE > clause by checking if the query starts with one of the known keywords > (like SELECT). I have a TODO item to recognize some additional database- > specific keywords (like WITH). > > I?ve run into this limitation again, this time in the context of a > WITH RECURSIVE ? query that I don?t think can be accomplished any > other way. I upgraded to ODB 2.5.0-b.27 but it seems the issue is > still there. > > Any chance we might be able to get a patch to loosen up these restrictions? Ok, I went ahead and added WITH as a recognized SELECT prefix (I see it's also supported by SQLite). Plus I've added the /*SELECT*/ prefix as a hint that what follows is a SELECT-like query (this is similar to the /*CALL*/ hint we use to distinguish procedure calls in PostgreSQL, which uses SELECT for everything). If you want to give it a try, I've published the snapshot packages here: https://queue.stage.build2.org Simply replace: https://pkg.cppget.org/1/beta with: https://queue.stage.build2.org/1/alpha in the bpkg commands when building ODB. Let me know if there any issues. From boris at codesynthesis.com Wed Jul 31 09:47:56 2024 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 31 09:47:33 2024 Subject: [odb-users] querying object and loading into a stack variable, then setting its id to 0 and persisting In-Reply-To: References: Message-ID: MM writes: > [...] the tracer shows that the INSERT INTO query still uses the > 'id' column? > > From a first look as to how I wrote the Base::id member pragma, do you > think the generated SQL stmt should not use column id because the database > will take care of that? No, this is expected. In SQLite, to get an auto-generated id, you insert a NULL value into the corresponding column (and if you insert a non-NULL value, then SQLite uses your value, so you can have it both ways at the same time). I looked through the generated code for your example and I don't see anything wrong with it. You can see the id image is unconditionally set to NULL in the generated persist() function for Derived. Are you actually observing wrong values in the database or are you basing your assumption that something is wrong merely on the fact that id is present in INSERT? From finjulhich at gmail.com Wed Jul 31 14:15:52 2024 From: finjulhich at gmail.com (MM) Date: Wed Jul 31 14:16:24 2024 Subject: [odb-users] querying object and loading into a stack variable, then setting its id to 0 and persisting Message-ID: >> [...] the tracer shows that the INSERT INTO query still uses the >> 'id' column? >> >> From a first look as to how I wrote the Base::id member pragma, do you >> think the generated SQL stmt should not use column id because the database >> will take care of that? >No, this is expected. In SQLite, to get an auto-generated id, you insert >a NULL value into the corresponding column (and if you insert a non-NULL >value, then SQLite uses your value, so you can have it both ways at the >same time). >I looked through the generated code for your example and I don't see >anything wrong with it. You can see the id image is unconditionally >set to NULL in the generated persist() function for Derived. >Are you actually observing wrong values in the database or are you >basing your assumption that something is wrong merely on the fact >that id is present in INSERT? I load 1 object with Derived d; db.query_one(..., d) which returns true, and a Derived object is loaded. Then I change d's attributes, in particular I set d.id to 0, and other attributes, then call db.persist(d); This inserted a row with id 0, then the next time around "duplicate" because id is already present I mean this is really the crux of the question. How do I load a row into d, "copy" it to another row, with the id being automatic, how to set id to NULL? The question is both sqlite and portsgresl. the id is of c++ type std::uint64_t