From mkarth3 at gmail.com Tue Dec 2 22:08:55 2014 From: mkarth3 at gmail.com (Karthikeyan Mahadevan) Date: Tue Dec 2 22:09:03 2014 Subject: [odb-users] Support for ODB on QNX Message-ID: Hi all, Has any one tried to cross compile odb for QNX? Appreciate if you could share the notes on this. regards, Karthikeyan M From truthset at gmail.com Wed Dec 3 02:48:30 2014 From: truthset at gmail.com (Jeff Waller) Date: Wed Dec 3 02:48:39 2014 Subject: [odb-users] deleting the underlying database while the program is running -- Windows Message-ID: <7C2B0989-CB5C-47FE-A10F-AC4480BC20E2@gmail.com> So perhaps a rare thing. But we have an application that as an extreme fallback deletes all metadata including the sqlite database being used. It just simply deletes the entire directory where all the metadata exists. This is done while the application is running but after all the threads that use the database are stopped and the database object is destructed. This has not been a problem because the application has historically been running on OS/X and Linux, but now it?s been successfully ported to Windows as well, and the Windows OS prevents deleting files while the file is still open by some program. Some residual open connection pool file descriptor even though the database is deleted might explain this, or an underlying bug in the app that keeps some reference available; but whatever the reason it prevents deletion of the database file. We have a pretty wide latitude to change things, EXCEPT for stopping the app itself; that is not allowed. Looking for any tips. -Jeff From boris at codesynthesis.com Wed Dec 3 07:11:27 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 3 12:09:20 2014 Subject: [odb-users] Support for ODB on QNX In-Reply-To: References: Message-ID: Hi Karthikeyan, Karthikeyan Mahadevan writes: > Has any one tried to cross compile odb for QNX? Appreciate if you could > share the notes on this. While I haven't tried to do it myself, I believe is should be virtually identical to doing it for ARM/Raspberry Pi: http://wiki.codesynthesis.com/Using_ODB_on_Mobile_and_Embedded_Systems If you decide to give it a try and run into any issues, feel free to post to odb-users for help (I still have a QNX VM and dev environment laying around somewhere). Boris From boris at codesynthesis.com Wed Dec 3 07:26:32 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 3 12:24:07 2014 Subject: [odb-users] deleting the underlying database while the program is running -- Windows In-Reply-To: <7C2B0989-CB5C-47FE-A10F-AC4480BC20E2@gmail.com> References: <7C2B0989-CB5C-47FE-A10F-AC4480BC20E2@gmail.com> Message-ID: Hi Jeff, Jeff Waller writes: > Some residual open connection pool file descriptor even though the > database is deleted might explain this, or an underlying bug in the > app that keeps some reference available; but whatever the reason it > prevents deletion of the database file. If you managed to delete the database instance, then this means all the connections have been closed since the connection_pool's destructor will wait for all the connections to be returned to the pool. One thing that can happen (see documentation for sqlite3_close()) is that SQLite might refuse to close the connection in certain cases. The ODB runtime does assert(false) in this case so you may want to build your application without NDEBUG defined and check that this is not the cause of your problem (by default the VC++ Debug build is built without NDEBUG and Release -- with). Other than that, the only thing to try that I can think of is to call sqlite3_shutdown() and see if that helps. Boris From mkarth3 at gmail.com Wed Dec 3 13:04:25 2014 From: mkarth3 at gmail.com (Karthikeyan Mahadevan) Date: Wed Dec 3 13:04:33 2014 Subject: [odb-users] Support for ODB on QNX In-Reply-To: References: Message-ID: Boris, Thank you for the reply. Yes, I have been trying based on the link. Just was not sure on the destination platform key word. Like in the below step to build sqllite, arm-bcm2708hardfp-linux-gnueabi, I have my platform to be qnx and x86. ./configure CFLAGS="-Os -DSQLITE_ENABLE_UNLOCK_NOTIFY=1" --disable-shared --host=arm-bcm2708hardfp-linux-gnueabi --prefix=`pwd`/../install I will start again and see how it goes. I was using mingw. My development platform is Windows and destination is QNX. regards, Karthikeyan M On Wed, Dec 3, 2014 at 4:11 AM, Boris Kolpackov wrote: > Hi Karthikeyan, > > Karthikeyan Mahadevan writes: > > > Has any one tried to cross compile odb for QNX? Appreciate if you could > > share the notes on this. > > While I haven't tried to do it myself, I believe is should be virtually > identical to doing it for ARM/Raspberry Pi: > > http://wiki.codesynthesis.com/Using_ODB_on_Mobile_and_Embedded_Systems > > If you decide to give it a try and run into any issues, feel free > to post to odb-users for help (I still have a QNX VM and dev > environment laying around somewhere). > > Boris > From mkarth3 at gmail.com Wed Dec 3 23:01:09 2014 From: mkarth3 at gmail.com (Karthikeyan Mahadevan) Date: Wed Dec 3 23:01:17 2014 Subject: [odb-users] Support for ODB on QNX In-Reply-To: References: Message-ID: Boris, Thank you for your support. I tried again on a qnx platform and I got the following error. ac_nonexistent.h file missing error is generated in the cofig.log while trying to run configure for the libodb-sqlite-2.3.0. This leads to "error: libsqlite3 is not found;" and eventually this is leading to "configure: exit 1". regards, Karthikeyan M On Wed, Dec 3, 2014 at 10:04 AM, Karthikeyan Mahadevan wrote: > Boris, > Thank you for the reply. > Yes, I have been trying based on the link. Just was not sure on the > destination platform key word. Like in the below step to build sqllite, arm-bcm2708hardfp-linux-gnueabi, > I have my platform to be qnx and x86. > > ./configure CFLAGS="-Os -DSQLITE_ENABLE_UNLOCK_NOTIFY=1" --disable-shared --host=arm-bcm2708hardfp-linux-gnueabi --prefix=`pwd`/../install > > I will start again and see how it goes. I was using mingw. My development > platform is Windows and destination is QNX. > > regards, > Karthikeyan M > > > On Wed, Dec 3, 2014 at 4:11 AM, Boris Kolpackov > wrote: > >> Hi Karthikeyan, >> >> Karthikeyan Mahadevan writes: >> >> > Has any one tried to cross compile odb for QNX? Appreciate if you could >> > share the notes on this. >> >> While I haven't tried to do it myself, I believe is should be virtually >> identical to doing it for ARM/Raspberry Pi: >> >> http://wiki.codesynthesis.com/Using_ODB_on_Mobile_and_Embedded_Systems >> >> If you decide to give it a try and run into any issues, feel free >> to post to odb-users for help (I still have a QNX VM and dev >> environment laying around somewhere). >> >> Boris >> > > From boris at codesynthesis.com Thu Dec 4 07:31:31 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Dec 4 07:39:50 2014 Subject: [odb-users] Support for ODB on QNX In-Reply-To: References: Message-ID: Hi Karthikeyan, Karthikeyan Mahadevan writes: > Just was not sure on the destination platform key word. Like in the > below step to build sqllite, arm-bcm2708hardfp-linux-gnueabi, I have > my platform to be qnx and x86. That's easy: run your gcc cross-compiler with the -v option and then look for the line starting with 'Target:'. In your case it should be something like i686-qnx or i386-unknown-qnx. > I tried again on a qnx platform and I got the following error. Are you building on the QNX target itself? If so, this is a bad idea for multiple reasons (e.g., you will never be able to run the ODB compiler on QNX so you will have to keep copying generated files from another machine). The way to go is to cross-compile. > ac_nonexistent.h file missing error is generated in the cofig.log while > trying to run configure for the libodb-sqlite-2.3.0. This leads to "error: > libsqlite3 is not found;" It looks like configure could not find SQLite headers. There could be multiple reasons why this happened, ranging from you not building SQLite to not installing it properly. I suggest that you do two things: 1. Go back to the cross-compilation approach and follow the Wiki guide. 2. If something doesn't work, send the complete list of steps that you have performed up to that point. And I mean everything, starting from how you built SQLite. Otherwise I can only guess what could have gone wrong (like above). Boris From axel50397 at gmail.com Sat Dec 6 06:07:04 2014 From: axel50397 at gmail.com (Adnan RIHAN) Date: Sat Dec 6 06:07:30 2014 Subject: [odb-users] Raw SQL statement Message-ID: Hi there, Long time no see! Today is the first day I need to do a raw SQL query on Sqlite database. Actually, I simply need to do a ?COUNT(*)... WHERE ...?. I thought about using ?result::size? but unfortunately, libodb-sqlite doesn?t support it (according to the doc: http://www.codesynthesis.com/products/odb/doc/manual.xhtml#21.5.1) So I?m looking for a way to query the database for 1 named column, but I can?t find how (except using views and adding structures). Is that possible ? Thank you. -- Cordialement, Adnan RIHAN. Directeur-G?rant de Eolis-Software, soci?t? de services informatiques. GPG: 5675-62BA (https://keybase.io/max13/key.asc) -> Si vous n'utilisez pas GPG mais souhaitez quand m?me m?envoyer un e-mail chiffr?: (https://encrypt.to/0x567562BA). From ajl17 at case.edu Fri Dec 5 16:45:28 2014 From: ajl17 at case.edu (Alexander Lonsberry) Date: Sat Dec 6 11:57:53 2014 Subject: [odb-users] Failed odb-tests at "callback" In-Reply-To: References: Message-ID: Thanks so very much. This fixed it. -Alex On Mon, Nov 24, 2014 at 4:52 AM, Boris Kolpackov wrote: > Hi Alexander, > > Alexander Lonsberry writes: > > > I cannot get past the "callback" test when I run "make check" > > > > *My Machine*: > > Windows 7 running MSYS with 64bit MinGW (tdm64-gcc-4.8.1-3). > > > > *Database* > > PostgreSQL Version 9.3.5 64bit > > > > *ODB C++* > > odb-2.3.0, libodb-2.3.0, libodb-pgsql-2.3.1, odb-tests-2.3.0 > > > > I run configure and make without a problem, however I then run make check > > and get an error. I have attached a text file of the output. > > Thanks for the information and the output. I am pretty sure this > has to do with differences in newlines. Try to re-configure the > tests with these DIFFFLAGS: > > ./configure ... DIFFFLAGS=-ubB > > This is how we run ODB tests on MinGW and everything works fine. > > Boris > > From vaw4 at case.edu Fri Dec 5 17:01:25 2014 From: vaw4 at case.edu (Vickie Webster) Date: Sat Dec 6 11:57:53 2014 Subject: [odb-users] Problem trying to use bidirectional relationships, composite ids, and lazy weak pointers Message-ID: Hello, I am working on a project where I am trying to set up a bidirectional relationship between two objects, one of which has a composite ID. I have included the .hxx file and my driver file below. I am using Windows 7, msys with 64 bit minGW (tdm64-gcc-4.8.1-3), and postgres ver 9.3.5 (64 bit). I am using odb 2.3.0. When I compile my .hxx file I am warned the "value type that is used as object id in persistent class with session support does not define the less than (<) comparison" and told to "provide operator< for this value type". I have included screen shots of compile errors below for clarity. I then wrote an operator< finction for this id type and the .hxx compiles. I then get a warning when I try to compile the generated localobjects-odb.cxx file that "void odb::lazy_ptr_base::reset_id() redeclared without dllimport attribute after being referenced with dll linkage [enabled by default]", however the file does compile. Finally, when I try to run the driver I end up with the error "multiple definition of 'operator<(routingID,routingID)'". I have previously successfully written and run code to handle unidirectional relationships and would greatly appreciate any help on this matter. Please let me know if you need any other information. Thank you, Vickie Webster Case Western Reserve University -------------- next part -------------- A non-text attachment was scrubbed... Name: Support Request.zip Type: application/zip Size: 87789 bytes Desc: not available Url : http://codesynthesis.com/pipermail/odb-users/attachments/20141205/9a67c779/SupportRequest-0001.zip From boris at codesynthesis.com Mon Dec 8 06:34:52 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 8 06:43:26 2014 Subject: [odb-users] Problem trying to use bidirectional relationships, composite ids, and lazy weak pointers In-Reply-To: References: Message-ID: Hi Vickie, Vickie Webster writes: > I have included screen shots of compile errors below for clarity. Never send screenshots of the errors to this mailing list. Instead, copy and paste the text. See the posting guidelines for details: http://codesynthesis.com/support/posting-guidelines.xhtml > Finally, when I try to run the driver I end up with the error "multiple > definition of 'operator<(routingID,routingID)'". > > bool operator<(const routingID routeID, routingID value) > { > return true; > } You have a non-inline function defined in the header file. Duplicate definitions is the expected result. Also note that the implementation of your operator< (always returning true) is wrong. Boris From boris at codesynthesis.com Mon Dec 8 06:39:27 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 8 06:47:59 2014 Subject: [odb-users] Raw SQL statement In-Reply-To: References: Message-ID: Hi Adnan, Adnan RIHAN writes: > I simply need to do a ?COUNT(*)... WHERE ...?. > > So I?m looking for a way to query the database for 1 named column, > but I can?t find how (except using views and adding structures). > > Is that possible ? Yes, using views: #pragma db view object(person) struct person_count { #pragma db column("COUNT(" + person::id_ + ")") std::size_t count; }; typedef odb::query query; db.query (query::name == "John"); Or: #pragma db view struct some_count { std::size_t count; }; db.query ("SELECT COUNT(*) WHERE ... "); Boris From axel50397 at gmail.com Mon Dec 8 06:51:28 2014 From: axel50397 at gmail.com (Adnan RIHAN) Date: Mon Dec 8 06:51:48 2014 Subject: [odb-users] Raw SQL statement In-Reply-To: References: Message-ID: ? Hi Boris, On 8 d?cembre 2014 at 12:47:59, Boris Kolpackov (boris@codesynthesis.com(mailto:boris@codesynthesis.com)) wrote: > Yes, using views: Thats what I saw in the documentation. I thought there was a way to query arbitrary queries without creating structures/classes. But then, as I?m using Qt, I can directly send raw queries if I need. Thanks. -- Cordialement, Adnan RIHAN. Directeur-G?rant de Eolis-Software, soci?t? de services informatiques. GPG: 5675-62BA (https://keybase.io/max13/key.asc) -> Si vous n'utilisez pas GPG mais souhaitez quand m?me m?envoyer un e-mail chiffr?: (https://encrypt.to/0x567562BA). From boris at codesynthesis.com Mon Dec 8 06:49:36 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 8 06:58:08 2014 Subject: [odb-users] Raw SQL statement In-Reply-To: References: Message-ID: Hi Adnan, Adnan RIHAN writes: > Thats what I saw in the documentation. I thought there was a way to > query arbitrary queries without creating structures/classes. There is, called database::execute(). But if your query needs to return something other than the row count, then you have to use a view which extracts the returned data into a struct. As my second example shows, you can have a single struct that can be used with different COUNT-based queries. Boris From axel50397 at gmail.com Mon Dec 8 07:01:28 2014 From: axel50397 at gmail.com (Adnan RIHAN) Date: Mon Dec 8 07:01:48 2014 Subject: [odb-users] Raw SQL statement In-Reply-To: References: Message-ID: On 8 d?cembre 2014 at 12:58:08, Boris Kolpackov (boris@codesynthesis.com(mailto:boris@codesynthesis.com)) wrote: > There is, called database::execute(). But if your query needs to > return something other than the row count, then you have to use > a view which extracts the returned data into a struct. As my > second example shows, you can have a single struct that can be > used with different COUNT-based queries. I understood that too :). I may count rows, or get 1 cell of a elaborated query (with many joins for instance). I?ll write some structs. Thx. -- Cordialement, Adnan RIHAN. Directeur-G?rant de Eolis-Software, soci?t? de services informatiques. GPG: 5675-62BA (https://keybase.io/max13/key.asc) -> Si vous n'utilisez pas GPG mais souhaitez quand m?me m?envoyer un e-mail chiffr?: (https://encrypt.to/0x567562BA). From axel50397 at gmail.com Thu Dec 11 05:15:26 2014 From: axel50397 at gmail.com (Adnan RIHAN) Date: Thu Dec 11 05:15:51 2014 Subject: [odb-users] Raw SQL statement In-Reply-To: References: Message-ID: Hi Boris, I have another question related to this one and your most interesting answer: On 8 d?cembre 2014 at 12:47:59, Boris Kolpackov (boris@codesynthesis.com(mailto:boris@codesynthesis.com)) wrote: > #pragma db view object(person) > struct person_count > { > #pragma db column("COUNT(" + person::id_ + ")") > std::size_t count; > }; > > typedef odb::query query; > > db.query (query::name == "John?); Let?s say, I have an Invoice table and a Warehouse table. An Invoice can have 2 types: ?Sell? and ?Inventory? (The first one is obvious, while the second one is to know my current stock). ?--------- | Invoice | |---------| | - _id_ ?| | - type ?| | - date ?| ?--------- class Invoice { ? ? uint32 ? ? m_id; ? ? QString ? ?m_type; ? ? QDateTime ?m_date; } ?----------- | Warehouse | |-----------| | - _date1_ | | - _date2_ | ?----------- class Warehouse { ? ? QDateTime ?m_openDate; ?// [date1] ? ? QDateTime ?m_closeDate; // [date2] ? ? Invoice ? ?m_lastStock; // SELECT `id` ? ? ? ? ? ? ? ? ? ? ? ? ? ? // FROM `invoices` ? ? ? ? ? ? ? ? ? ? ? ? ? ? // WHERE `type` == 'Inventory' ? ? ? ? ? ? ? ? ? ? ? ? ? ? // AND `date` > [date1] ? ? ? ? ? ? ? ? ? ? ? ? ? ? // AND `date` < [date2] } The SQL query is there to know what would be the ?query? if I had to write it. Is it possible for ODB, when querying a Warehouse, to automatically set the ?m_lastStock?? I see approximately how it could be done with views, but I don?t see how to tell ODB to find an invoice base on the class date (without manually writing it as an odb::query<>()). Thanks for your help. -- Cordialement, Adnan RIHAN. Directeur-G?rant de Eolis-Software, soci?t? de services informatiques. GPG: 5675-62BA (https://keybase.io/max13/key.asc) -> Si vous n'utilisez pas GPG mais souhaitez quand m?me m?envoyer un e-mail chiffr?: (https://encrypt.to/0x567562BA). From boris at codesynthesis.com Thu Dec 11 07:28:34 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Dec 11 07:37:07 2014 Subject: [odb-users] Raw SQL statement In-Reply-To: References: Message-ID: Hi Adnan, Adnan RIHAN writes: > The SQL query is there to know what would be the ?query? if I had to > write it. Is it possible for ODB, when querying a Warehouse, to > automatically set the ?m_lastStock?? You can make m_lastStock transient and then load it from the database operation callback (e.g., post_load) with a custom query. Boris From picserez at gmail.com Thu Dec 11 17:19:06 2014 From: picserez at gmail.com (Erez Pics) Date: Fri Dec 12 04:41:25 2014 Subject: [odb-users] Temp Ids Message-ID: Hi Boris, Thank you very much for your help, we managed to find our concurrency problem and things seems to work good now :-) Our software needs to assign temp Ids to objects, the objects need to behave exactly like regular permanent ones in terms of save\load\query etc' At some point the objects are either given a permanent ID or deleted. I thought of using a different segment for temp objects, for example: * Permanent objects identifiers will be positive from 1 and on (1,2,3,4....) * Temp objects identifiers will be negative from -1000 and on (-1000,-1001,-1002,-1003...) * The code is issuing valid consecutive positive or negative identifiers, I am not using SQLite auto numbering for these tables. I would be happy to hear if you find a problem in using negative identifiers: 1) Is there a problem using negative and positive identifiers together with SQLite and ODB ? 2) Assuming it's legal, and we decide to update a temp identifier to permanent, ON UPDATE CASCADE is enough to automatically update all dependent FKs ? Thank you very VERY much, Erez. From Mikhail.Tomilov at infotecs.ru Fri Dec 12 03:04:24 2014 From: Mikhail.Tomilov at infotecs.ru (Tomilov.Mikhail) Date: Fri Dec 12 04:41:26 2014 Subject: [odb-users] Polymorphic code generation problem on PostgreSQL Message-ID: <548AA188.4030808@infotecs.ru> Hello! I use ODB with Postgresql. Here is ODB entities: #include #include #include #pragma db object table( "contrator" ) polymorphic struct Contrator { ? virtual ~Contrator() {} ? #pragma db id ? int id; ? std::string name; }; #pragma db object table( "company" ) struct Company : public Contrator { ? int size; }; #pragma db object table( "government" ) struct Government : public Contrator { ? int code; }; #pragma db object table( "person" ) struct Person { ? #pragma db id ? int id; ? int contractor_id; }; #pragma db object table( "workflow" ) struct Workflow { ? #pragma db id ? int id; }; #pragma db object table( "transaction" ) struct Transaction { ? #pragma db id ? int id; ? int sender_id; ? int recipient_id; ? int workflow_id; }; #pragma db view object( Workflow ) \ ? object( Transaction: Transaction::workflow_id == Workflow::id ) \ ? object( Person = Sender: Transaction::sender_id == Sender::id ) \ ? object( Person = Recipient: Transaction::recipient_id == Recipient::id ) \ ? object( Company = SenderCompany: SenderCompany::id == Sender::contractor_id ) \ ? object( Government = RecipientGovernment: RecipientGovernment::id == Recipient::contractor_id ) struct WorkflowView { ? #pragma db column (Workflow::id) ? int workflow_id; ? #pragma db column (Transaction::id) ? int transaction_id; ? #pragma db column (Sender::id) ? int sender_id; ? #pragma db column (Recipient::id) ? int recipient_id; ? #pragma db column (SenderCompany::name) ? std::string sender_name; ? #pragma db column (RecipientGovernment::name) ? std::string recipient_name; }; #include I load data this way: odb::pgsql::database conn("host=localhost port=5432 user=user password=123456 dbname=test"); odb::transaction tr(conn.begin()); typedef odb::query< WorkflowView > Query; tr.database().query< WorkflowView >(); I get postgresql error: "missing FROM-clause entry for table "SenderCompany_contrator" at character". Here is PostgreSQL query generated by ODB: 1:? SELECT 2:? ? ? "workflow"."id", "transaction"."id", "Sender"."id", "Recipient"."id", "SenderCompany_contrator"."name", "RecipientGovernment_contrator"."name" 3:? FROM "workflow" 4:? LEFT JOIN "transaction" ON "transaction"."workflow_id" = "workflow"."id" 5:? LEFT JOIN "person" AS "Sender" ON "transaction"."sender_id" = "Sender"."id" 6:? LEFT JOIN "person" AS "Recipient" ON "transaction"."recipient_id" = "Recipient"."id" 7:? LEFT JOIN "company" AS "SenderCompany_company" ON "SenderCompany_contrator"."id" = "Sender"."contractor_id" 8:? LEFT JOIN "contrator" AS "SenderCompany_contrator" ON "SenderCompany_contrator"."id"="SenderCompany_company"."id" 9:? LEFT JOIN "government" AS "RecipientGovernment_government" ON "RecipientGovernment_contrator"."id" = "Recipient"."contractor_id" 10: LEFT JOIN "contrator" AS "RecipientGovernment_contrator" ON "RecipientGovernment_contrator"."id"="RecipientGovernment_government"."id" At 7th line used while it is declared at 8th line. Is it entities declaration problem or ODB bug? Thank you! -- Best regards, Mikhail From boris at codesynthesis.com Fri Dec 12 04:39:39 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Dec 12 04:48:11 2014 Subject: [odb-users] Temp Ids In-Reply-To: References: Message-ID: Hi Erez, Erez Pics writes: > 1) Is there a problem using negative and positive identifiers together > with SQLite and ODB ? I don't think there will be any. > 2) Assuming it's legal, and we decide to update a temp identifier to > permanent, ON UPDATE CASCADE is enough to automatically update all > dependent FKs ? I think so, though ODB currently has no support for adding the ON UPDATE clause in the generated schema (added to the TODO list). Also, it seems to me there is a lot simpler way to achieve what you want: a bool 'temporary' flag in the object. This way you don't need to mess with updating foreign keys, etc. And you can use auto ids. Boris From axel50397 at gmail.com Fri Dec 12 05:02:58 2014 From: axel50397 at gmail.com (Adnan RIHAN) Date: Fri Dec 12 05:03:23 2014 Subject: [odb-users] Raw SQL statement In-Reply-To: References: Message-ID: Hi Boris, Perfect solution, thank you :) On 11 d?cembre 2014 at 13:37:07, Boris Kolpackov (boris@codesynthesis.com) wrote: Adnan RIHAN writes:? > The SQL query is there to know what would be the ?query? if I had to > write it. Is it possible for ODB, when querying a Warehouse, to > automatically set the ?m_lastStock?? You can make m_lastStock transient and then load it from the database operation callback (e.g., post_load) with a custom query. Boris --? Cordialement, Adnan RIHAN. Directeur-G?rant de?Eolis-Software,?soci?t? de services informatiques. GPG:?5675-62BA (https://keybase.io/max13/key.asc) ->?Si vous?n'utilisez?pas GPG mais?souhaitez quand m?me m?envoyer un?e-mail chiffr?: (https://encrypt.to/0x567562BA). From picserez at gmail.com Fri Dec 12 16:20:35 2014 From: picserez at gmail.com (Erez Pics) Date: Mon Dec 15 05:55:24 2014 Subject: [odb-users] Temp Ids In-Reply-To: References: Message-ID: Hi Boris, Thank you for your quick response. The idea to use temp ids allow us to use real object connections, real objects and real queries, meaning, it's a complex object model in which temp objects are connected to other temp objects and to permanent existing objects. Using temp Ids, we keep using the DB as the backend infrastructure for persisting and fetching all objects, without it we would probably need to implement a separate flow to all temp object maintaining all their hierarchy and logic paths as their permanent counterparts. Thank you very much, Erez. On Fri, Dec 12, 2014 at 11:39 AM, Boris Kolpackov wrote: > Hi Erez, > > Erez Pics writes: > >> 1) Is there a problem using negative and positive identifiers together >> with SQLite and ODB ? > > I don't think there will be any. > > >> 2) Assuming it's legal, and we decide to update a temp identifier to >> permanent, ON UPDATE CASCADE is enough to automatically update all >> dependent FKs ? > > I think so, though ODB currently has no support for adding the ON > UPDATE clause in the generated schema (added to the TODO list). > > Also, it seems to me there is a lot simpler way to achieve what > you want: a bool 'temporary' flag in the object. This way you don't > need to mess with updating foreign keys, etc. And you can use auto > ids. > > Boris From boris at codesynthesis.com Mon Dec 15 06:55:48 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 15 07:04:21 2014 Subject: [odb-users] Polymorphic code generation problem on PostgreSQL In-Reply-To: <548AA188.4030808@infotecs.ru> References: <548AA188.4030808@infotecs.ru> Message-ID: Hi Mikhail, Tomilov.Mikhail writes: > 7:? LEFT JOIN "company" AS "SenderCompany_company" ON > "SenderCompany_contrator"."id" = "Sender"."contractor_id" This should be: "SenderCompany_company"."id" = "Sender"."contractor_id" > Is it entities declaration problem or ODB bug? That's a bug in ODB. Thanks for the report and the test case! The fix is in the repository: scm.codesynthesis.com/?p=odb/odb.git;a=commit;h=0e1f5c435f4f1f99211654c30bf363f7ceed8ef1 I can also build you a pre-release binary if you would like (let me know which platform). Boris From grosr.romain at gmail.com Sun Dec 14 13:33:08 2014 From: grosr.romain at gmail.com (Romain Gros) Date: Mon Dec 15 08:26:57 2014 Subject: [odb-users] Request return different results if executed in command line Message-ID: Hi, I am experiencing something weird with ODB right now, you will find the code/view/data and the test case at the end. I made an SQL request and it works fine, I got the behavior that I want. I made an ODB view based on the sql request, and the output SQL statement is the same as the handmade request. But my view, when executed, doesn't get me the same results! I have the same sql output, but not the same results and it seems really weird. In my request, I use 2 left joins to check if the corresponding record doesn't exist, but it's like they are being ignored. I am experiencing this problem on MySQL and PostgreSQL. Do I do something wrong here? Thanks a lot, Romain Gros PS: Sorry for the long post, I really am in the dark here. PPS: I had another quick question, is it possible to make sub-queries in the where clause using ODB instead of writing pure sql in the query ? ===== Code ===== ---- The SQL, generate by odb : ---- SELECT `qs`.`idquest`, MIN(`qs`.`steporder`) FROM `queststep` AS `qs` LEFT JOIN `quest` AS `q` ON `qs`.`idquest` = `q`.`idquest` LEFT JOIN `characterdonequeststep` AS `cdqs` ON `cdqs`.`idqueststep` = `qs`.`idqueststep` AND `cdqs`.`idcharacter` = 2 LEFT JOIN `characterownedquest` AS `coq` ON `coq`.`idqueststep` = `qs`.`idqueststep` AND `coq`.`idcharacter` = 2 WHERE ( ( (`q`.`level` <= 1) AND (`cdqs`.`idqueststep` IS NULL) ) AND (`coq`.`idqueststep` IS NULL) ) GROUP BY `qs`.`idquest` ---- The view ---- # pragma db view \ object(QuestStep = qs) \ object(Quest = q: qs::_quest) \ object(CharacterDoneQuestStep = cdqs: cdqs::_idcharacterdonequeststep._idqueststep + "=" + qs::_idqueststep + " AND " + cdqs::_idcharacterdonequeststep._idcharacter + " = " + odb::query::_ref(AvailableQuestStep_idCharacter)) \ object(CharacterOwnedQuest = coq: coq::_idcharacterownedquest._idqueststep + "=" + qs::_idqueststep + " AND " + coq::_idcharacterownedquest._idcharacter + " = " + odb::query::_ref(AvailableQuestStep_idCharacter)) \ query(((?) \ && cdqs::_idcharacterdonequeststep._idqueststep.is_null() \ && coq::_idcharacterownedquest._idqueststep.is_null()) \ + "GROUP BY" + qs::_quest) struct AvailableQuestStep { # pragma db column(qs::_quest) int _idquest; # pragma db column("min(" + qs::_steporder + ")") int _steporder; }; ---- Objets ---- The QuestStep has a reference to the Quest. The CharacterDoneQuestStep and CharacterOwnedQuest contain a composite id. If needed, I can show the source but I didn't want to put too much here. ---- Database ---- In my example, I have: 3 Quests: id [4, 5, 6] (level 1) 3 QuestSteps: - id: 9, quest: 4 - id: 10, quest: 5 - id: 11, quest: 6 0 CharacterDoneQuestStep 1 CharacterOwnedQuest: - idcharacter: 2, idqueststep: 9 ===== Test case ===== Executing the above request give me: - idquest: 5, min(): 0 - idquest: 6, min(): 0 Which is good because the Character already owns the QuestStep 9. But when I run it with ODB, it gives me: - idquest: 4, min(): 0 - idquest: 5, min(): 0 - idquest: 6, min(): 0 Which is not what I want. From boris at codesynthesis.com Mon Dec 15 08:41:06 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 15 08:49:38 2014 Subject: [odb-users] Request return different results if executed in command line In-Reply-To: References: Message-ID: Hi Romain, Romain Gros writes: > I am experiencing this problem on MySQL and PostgreSQL. If you get the same difference in behavior using both databases then there is definitely some logical difference between the two queries that you are running. It is very unlikely to be a bug in the runtime or a configuration issue. One thing that you can do is to try to simplify the query by going back one step at a time and see where the difference disappears (or you get the result that you would expect). For example, remove aggregation and see if you get the expected number of rows. If that doesn't help, then I would need a complete working example that reproduces the problem. In the fragments that you have provided I don't see anything wrong. > PPS: I had another quick question, is it possible to make sub-queries in > the where clause using ODB instead of writing pure sql in the query? There is no direct support yet but you should be able to write them using the mixed style (e.g., using C++ identifier for column names, etc). Boris From christian at gsvitec.com Mon Dec 15 12:56:31 2014 From: christian at gsvitec.com (Christian Sell) Date: Mon Dec 15 12:56:24 2014 Subject: [odb-users] compiling under MinGW w/ CMake Message-ID: <002901d01890$7557f400$6007dc00$@gsvitec.com> Hello, what a cocktail! MinGw 4.8 + Odb + CMake! I have a simple project setup with the above ingredients. I am able to build now (took me waaay too long), but as soon as I add a shared_ptr member (along with the appropriate #include and using clause), I get a message "shared_ptr does not name a type" Not being lazy, I figure out the include path for MinGW (why the h*** isn't it passed to the odb compiler automatically?) and pass it via -I to the odb compiler. Now it gets interesting: 300 lines of obscure error messages, of which I include just the first few: In file included from C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/string:41:0, from :7: C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected template-name before '<' token C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected '{' before '<' token C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected unqualified-id before '<' token In file included from C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/string:41:0, from :7: can someone shed light on this? Regards, Chris From christian at gsvitec.com Tue Dec 16 04:20:05 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 16 04:19:57 2014 Subject: AW: [odb-users] compiling under MinGW Message-ID: <000201d01911$7abb0640$703112c0$@gsvitec.com> As an addendum: trying to use the include files from the mingw that comes with the precompiled odb distribution yields even more problems (at first shared_ptr unknown, after defining __GXX_EXPERIMENTAL_CXX0X__ errors abound). Trying to use the completely outdated mingw compiler from the odb distro is not an option. Seems like we're lost with mingw32 and odb. When I first saw the ODB pragma syntax, I was intrigued by the approach for maintaining mapping info. Meanwhile, I am not sure at all.. -----Urspr?ngliche Nachricht----- Von: odb-users-bounces@codesynthesis.com [mailto:odb-users-bounces@codesynthesis.com] Im Auftrag von Christian Sell Gesendet: Montag, 15. Dezember 2014 18:57 An: odb-users@codesynthesis.com Betreff: [odb-users] compiling under MinGW w/ CMake Hello, what a cocktail! MinGw 4.8 + Odb + CMake! I have a simple project setup with the above ingredients. I am able to build now (took me waaay too long), but as soon as I add a shared_ptr member (along with the appropriate #include and using clause), I get a message "shared_ptr does not name a type" Not being lazy, I figure out the include path for MinGW (why the h*** isn't it passed to the odb compiler automatically?) and pass it via -I to the odb compiler. Now it gets interesting: 300 lines of obscure error messages, of which I include just the first few: In file included from C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/string:41:0, from :7: C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected template-name before '<' token C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected '{' before '<' token C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected unqualified-id before '<' token In file included from C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/string:41:0, from :7: can someone shed light on this? Regards, Chris From christian at gsvitec.com Tue Dec 16 04:54:59 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 16 04:54:51 2014 Subject: AW: [odb-users] compiling under MinGW In-Reply-To: <000201d01911$7abb0640$703112c0$@gsvitec.com> References: <000201d01911$7abb0640$703112c0$@gsvitec.com> Message-ID: <000401d01916$5aaaeaf0$1000c0d0$@gsvitec.com> And finally: the solution. Simply adding a "--std c++11" option (and removing the -I) did the job. -----Urspr?ngliche Nachricht----- Von: odb-users-bounces@codesynthesis.com [mailto:odb-users-bounces@codesynthesis.com] Im Auftrag von Christian Sell Gesendet: Dienstag, 16. Dezember 2014 10:20 An: odb-users@codesynthesis.com Betreff: AW: [odb-users] compiling under MinGW As an addendum: trying to use the include files from the mingw that comes with the precompiled odb distribution yields even more problems (at first shared_ptr unknown, after defining __GXX_EXPERIMENTAL_CXX0X__ errors abound). Trying to use the completely outdated mingw compiler from the odb distro is not an option. Seems like we're lost with mingw32 and odb. When I first saw the ODB pragma syntax, I was intrigued by the approach for maintaining mapping info. Meanwhile, I am not sure at all.. -----Urspr?ngliche Nachricht----- Von: odb-users-bounces@codesynthesis.com [mailto:odb-users-bounces@codesynthesis.com] Im Auftrag von Christian Sell Gesendet: Montag, 15. Dezember 2014 18:57 An: odb-users@codesynthesis.com Betreff: [odb-users] compiling under MinGW w/ CMake Hello, what a cocktail! MinGw 4.8 + Odb + CMake! I have a simple project setup with the above ingredients. I am able to build now (took me waaay too long), but as soon as I add a shared_ptr member (along with the appropriate #include and using clause), I get a message "shared_ptr does not name a type" Not being lazy, I figure out the include path for MinGW (why the h*** isn't it passed to the odb compiler automatically?) and pass it via -I to the odb compiler. Now it gets interesting: 300 lines of obscure error messages, of which I include just the first few: In file included from C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/string:41:0, from :7: C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected template-name before '<' token C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected '{' before '<' token C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/bits/allocator.h:92:45: error: expected unqualified-id before '<' token In file included from C:/MinGW/mingw32/lib/gcc/mingw32/4.8.1/include/c++/string:41:0, from :7: can someone shed light on this? Regards, Chris From Mikhail.Tomilov at infotecs.ru Mon Dec 15 09:34:43 2014 From: Mikhail.Tomilov at infotecs.ru (Tomilov.Mikhail) Date: Tue Dec 16 04:57:58 2014 Subject: [odb-users] Polymorphic code generation problem on PostgreSQL In-Reply-To: References: <548AA188.4030808@infotecs.ru> Message-ID: <548EF183.6020200@infotecs.ru> Hello Boris, It would be nice to get binary build for i686-windows and i686-linux-gnu. Thank you! On 15.12.2014 15:55, Boris Kolpackov wrote: > Hi Mikhail, > > Tomilov.Mikhail writes: > >> 7:? LEFT JOIN "company" AS "SenderCompany_company" ON >> "SenderCompany_contrator"."id" = "Sender"."contractor_id" > This should be: > > "SenderCompany_company"."id" = "Sender"."contractor_id" > > >> Is it entities declaration problem or ODB bug? > That's a bug in ODB. Thanks for the report and the test case! The > fix is in the repository: > > scm.codesynthesis.com/?p=odb/odb.git;a=commit;h=0e1f5c435f4f1f99211654c30bf363f7ceed8ef1 > > I can also build you a pre-release binary if you would like (let > me know which platform). > > Boris > -- ? ?????????, ??????? ??????. ??????? ???????????, ???????? ?InfoTeCS? (www.infotecs.ru) From boris at codesynthesis.com Tue Dec 16 04:57:58 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Dec 16 05:06:32 2014 Subject: [odb-users] compiling under MinGW In-Reply-To: <000401d01916$5aaaeaf0$1000c0d0$@gsvitec.com> References: <000201d01911$7abb0640$703112c0$@gsvitec.com> <000401d01916$5aaaeaf0$1000c0d0$@gsvitec.com> Message-ID: Hi Christian, Christian Sell writes: > And finally: the solution. Simply adding a "--std c++11" option (and > removing the -I) did the job. Yep, that's what I thought it was. > Trying to use the completely outdated mingw compiler from the odb > distro is not an option. Seems like we're lost with mingw32 and odb. > > When I first saw the ODB pragma syntax, I was intrigued by the approach for > maintaining mapping info. Meanwhile, I am not sure at all.. Next time, instead of spending time on making dramatic statements like these, I suggest that you provide more precise and detailed information about your situation. Things like "here is my source code", "here are the ODB and C++ compiler command lines I use", etc. When you say 'shared_ptr', it can be Boost shared_ptr, C++98 TR1 shared_ptr, or C++11 shared_ptr. Each of those cases would lead to a very different possible solution. So when I saw your email, I didn't really feel like guessing which one it was or, worse, describing possible next steps for each of them. So, next time, help me to help you by describing your situation precisely. Boris From christian at gsvitec.com Tue Dec 16 05:20:32 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 16 05:20:25 2014 Subject: AW: [odb-users] compiling under MinGW In-Reply-To: References: <000201d01911$7abb0640$703112c0$@gsvitec.com> <000401d01916$5aaaeaf0$1000c0d0$@gsvitec.com> Message-ID: <000801d01919$ec78c940$c56a5bc0$@gsvitec.com> > Yep, that's what I thought it was. Looking at it now, it was indeed fairly obvious from the "shared_ptr is not a type" message > So, next time, help me to help you by describing your situation precisely. That somewhat contradicts your first statement. You had an immediate guess, didn't want to answer until more details were provided, but didn't even ask for any. I think I had all required details, and it was my frustrated tone that put you off. From christian at gsvitec.com Tue Dec 16 06:57:54 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 16 06:57:47 2014 Subject: [odb-users] --odb-epilogue option Message-ID: <002101d01927$86cf0ec0$946d2c40$@gsvitec.com> Hello, I have an issue with the above option. We are trying to use it from within a CMake script, using the following expression: odb --std c++11 --database sqlite --cxx-suffix .cpp --hxx-suffix .h --generate-query --generate-schema --odb-epilogue "#include \"${pragmafile}\"" ${_file} the pragma file seems to be read ok, as syntax errors inside the file are flagged (e.g. as shown further below). However, I always get error messages shown below, and no files are generated: :1:9: error: #include expects "FILENAME" or This error appears along with the one above when I change the valid name "Camera" to invalid "Camera22" camera_pragmas.h:6:27: error: unable to resolve type name 'Camera22' in db pragma object Any clues? I have tried all reasonable permutations on this, to no avail. Regards, Christian From boris at codesynthesis.com Tue Dec 16 07:41:59 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Dec 16 07:50:31 2014 Subject: [odb-users] --odb-epilogue option In-Reply-To: <002101d01927$86cf0ec0$946d2c40$@gsvitec.com> References: <002101d01927$86cf0ec0$946d2c40$@gsvitec.com> Message-ID: Hi Christian, Christian Sell writes: > odb --std c++11 --database sqlite --cxx-suffix .cpp --hxx-suffix .h > --generate-query --generate-schema --odb-epilogue "#include > \"${pragmafile}\"" ${_file} Can you add the -v option to the above command line and then show the g++ command line that the ODB compiler prints (starts after the line saying "Compiling ${_file}"). Boris From christian at gsvitec.com Tue Dec 16 07:58:45 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 16 07:58:36 2014 Subject: AW: [odb-users] --odb-epilogue option In-Reply-To: References: <002101d01927$86cf0ec0$946d2c40$@gsvitec.com> Message-ID: <003001d01930$0693d2a0$13bb77e0$@gsvitec.com> Never mind. It was a matter of passing the quotes to the compiler, which can (only) be ensured by using the VERBATIM option on the CMake "add_custom_command" command, like so: foreach(_file ${ODB_INFILES}) string(REPLACE ".h" "-odb.cpp" gencppfile ${_file}) string(REPLACE ".h" "-odb.h" genhppfile ${_file}) string(REPLACE ".h" "_pragmas.h" pragmafile ${_file}) add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${gencppfile} COMMAND odb --std c++11 --database sqlite --cxx-suffix .cpp --hxx-suffix .h --generate-query --generate-schema --odb-epilogue "#include \"${pragmafile}\"" ${_file} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${_file} COMMENT "\nrunning odb on ${_file}" VERBATIM ) list(APPEND ODB_GENFILES ${gencppfile} ${genhppfile}) endforeach() -----Urspr?ngliche Nachricht----- Von: Boris Kolpackov [mailto:boris@codesynthesis.com] Gesendet: Dienstag, 16. Dezember 2014 13:42 An: Christian Sell Cc: odb-users@codesynthesis.com Betreff: Re: [odb-users] --odb-epilogue option Hi Christian, Christian Sell writes: > odb --std c++11 --database sqlite --cxx-suffix .cpp --hxx-suffix .h > --generate-query --generate-schema --odb-epilogue "#include > \"${pragmafile}\"" ${_file} Can you add the -v option to the above command line and then show the g++ command line that the ODB compiler prints (starts after the line saying "Compiling ${_file}"). Boris From info at peredin.com Tue Dec 16 08:03:52 2014 From: info at peredin.com (Per Edin) Date: Tue Dec 16 08:04:03 2014 Subject: [odb-users] --odb-epilogue option In-Reply-To: <003001d01930$0693d2a0$13bb77e0$@gsvitec.com> References: <002101d01927$86cf0ec0$946d2c40$@gsvitec.com> <003001d01930$0693d2a0$13bb77e0$@gsvitec.com> Message-ID: Hi Christian! Have you looked at https://github.com/BtbN/OdbCmake? /Per > On 16 Dec 2014, at 13:58, Christian Sell wrote: > > Never mind. It was a matter of passing the quotes to the compiler, which can > (only) be ensured by using the VERBATIM option on the CMake > "add_custom_command" command, like so: > > foreach(_file ${ODB_INFILES}) > string(REPLACE ".h" "-odb.cpp" gencppfile ${_file}) > string(REPLACE ".h" "-odb.h" genhppfile ${_file}) > string(REPLACE ".h" "_pragmas.h" pragmafile ${_file}) > add_custom_command( > OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${gencppfile} > COMMAND odb --std c++11 --database sqlite --cxx-suffix .cpp > --hxx-suffix .h --generate-query --generate-schema --odb-epilogue "#include > \"${pragmafile}\"" ${_file} > WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} > DEPENDS ${_file} > COMMENT "\nrunning odb on ${_file}" > VERBATIM > ) > list(APPEND ODB_GENFILES ${gencppfile} ${genhppfile}) > endforeach() > > -----Urspr?ngliche Nachricht----- > Von: Boris Kolpackov [mailto:boris@codesynthesis.com] > Gesendet: Dienstag, 16. Dezember 2014 13:42 > An: Christian Sell > Cc: odb-users@codesynthesis.com > Betreff: Re: [odb-users] --odb-epilogue option > > Hi Christian, > > Christian Sell writes: > >> odb --std c++11 --database sqlite --cxx-suffix .cpp --hxx-suffix .h >> --generate-query --generate-schema --odb-epilogue "#include >> \"${pragmafile}\"" ${_file} > > Can you add the -v option to the above command line and then show the g++ > command line that the ODB compiler prints (starts after the line saying > "Compiling ${_file}"). > > Boris > > From christian at gsvitec.com Tue Dec 16 08:06:28 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 16 08:06:20 2014 Subject: AW: [odb-users] --odb-epilogue option In-Reply-To: References: <002101d01927$86cf0ec0$946d2c40$@gsvitec.com> <003001d01930$0693d2a0$13bb77e0$@gsvitec.com> Message-ID: <003a01d01931$1aae8040$500b80c0$@gsvitec.com> Hello Per, I have looked at it, and wasn't able to get it to run. Also, I don?t think it's related to the issue I was having here, as it deals with discovering the ODB tools, not invoking them -Chris -----Urspr?ngliche Nachricht----- Von: Per Edin [mailto:info@peredin.com] Gesendet: Dienstag, 16. Dezember 2014 14:04 An: Christian Sell Cc: ODB Users Mailing List Betreff: Re: [odb-users] --odb-epilogue option Hi Christian! Have you looked at https://github.com/BtbN/OdbCmake? /Per > On 16 Dec 2014, at 13:58, Christian Sell wrote: > > Never mind. It was a matter of passing the quotes to the compiler, > which can > (only) be ensured by using the VERBATIM option on the CMake > "add_custom_command" command, like so: > > foreach(_file ${ODB_INFILES}) > string(REPLACE ".h" "-odb.cpp" gencppfile ${_file}) > string(REPLACE ".h" "-odb.h" genhppfile ${_file}) > string(REPLACE ".h" "_pragmas.h" pragmafile ${_file}) > add_custom_command( > OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${gencppfile} > COMMAND odb --std c++11 --database sqlite --cxx-suffix .cpp > --hxx-suffix .h --generate-query --generate-schema --odb-epilogue > "#include \"${pragmafile}\"" ${_file} > WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} > DEPENDS ${_file} > COMMENT "\nrunning odb on ${_file}" > VERBATIM > ) > list(APPEND ODB_GENFILES ${gencppfile} ${genhppfile}) > endforeach() > > -----Urspr?ngliche Nachricht----- > Von: Boris Kolpackov [mailto:boris@codesynthesis.com] > Gesendet: Dienstag, 16. Dezember 2014 13:42 > An: Christian Sell > Cc: odb-users@codesynthesis.com > Betreff: Re: [odb-users] --odb-epilogue option > > Hi Christian, > > Christian Sell writes: > >> odb --std c++11 --database sqlite --cxx-suffix .cpp --hxx-suffix .h >> --generate-query --generate-schema --odb-epilogue "#include >> \"${pragmafile}\"" ${_file} > > Can you add the -v option to the above command line and then show the > g++ command line that the ODB compiler prints (starts after the line > saying "Compiling ${_file}"). > > Boris > > From info at peredin.com Tue Dec 16 08:10:07 2014 From: info at peredin.com (Per Edin) Date: Tue Dec 16 08:10:15 2014 Subject: AW: [odb-users] --odb-epilogue option In-Reply-To: <003a01d01931$1aae8040$500b80c0$@gsvitec.com> References: <002101d01927$86cf0ec0$946d2c40$@gsvitec.com> <003001d01930$0693d2a0$13bb77e0$@gsvitec.com> <003a01d01931$1aae8040$500b80c0$@gsvitec.com> Message-ID: Hi, Yes, it discovers the ODB tools, but it can also invoke them. Take a look at the CMakeLists.txt file, it calls odb_compile. /Per On Dec 16, 2014 2:06 PM, "Christian Sell" wrote: > Hello Per, > > I have looked at it, and wasn't able to get it to run. Also, I don?t think > it's related to the issue I was having here, as it deals with discovering > the ODB tools, not invoking them > > -Chris > > -----Urspr?ngliche Nachricht----- > Von: Per Edin [mailto:info@peredin.com] > Gesendet: Dienstag, 16. Dezember 2014 14:04 > An: Christian Sell > Cc: ODB Users Mailing List > Betreff: Re: [odb-users] --odb-epilogue option > > Hi Christian! > > Have you looked at https://github.com/BtbN/OdbCmake? > > /Per > > On 16 Dec 2014, at 13:58, Christian Sell wrote: > > > > Never mind. It was a matter of passing the quotes to the compiler, > > which can > > (only) be ensured by using the VERBATIM option on the CMake > > "add_custom_command" command, like so: > > > > foreach(_file ${ODB_INFILES}) > > string(REPLACE ".h" "-odb.cpp" gencppfile ${_file}) > > string(REPLACE ".h" "-odb.h" genhppfile ${_file}) > > string(REPLACE ".h" "_pragmas.h" pragmafile ${_file}) > > add_custom_command( > > OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${gencppfile} > > COMMAND odb --std c++11 --database sqlite --cxx-suffix .cpp > > --hxx-suffix .h --generate-query --generate-schema --odb-epilogue > > "#include \"${pragmafile}\"" ${_file} > > WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} > > DEPENDS ${_file} > > COMMENT "\nrunning odb on ${_file}" > > VERBATIM > > ) > > list(APPEND ODB_GENFILES ${gencppfile} ${genhppfile}) > > endforeach() > > > > -----Urspr?ngliche Nachricht----- > > Von: Boris Kolpackov [mailto:boris@codesynthesis.com] > > Gesendet: Dienstag, 16. Dezember 2014 13:42 > > An: Christian Sell > > Cc: odb-users@codesynthesis.com > > Betreff: Re: [odb-users] --odb-epilogue option > > > > Hi Christian, > > > > Christian Sell writes: > > > >> odb --std c++11 --database sqlite --cxx-suffix .cpp --hxx-suffix .h > >> --generate-query --generate-schema --odb-epilogue "#include > >> \"${pragmafile}\"" ${_file} > > > > Can you add the -v option to the above command line and then show the > > g++ command line that the ODB compiler prints (starts after the line > > saying "Compiling ${_file}"). > > > > Boris > > > > > > > From christian at gsvitec.com Tue Dec 16 08:16:05 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 16 08:15:57 2014 Subject: [odb-users] odb-epilogue conclusions Message-ID: <004601d01932$72c078a0$584169e0$@gsvitec.com> Hello, after having solved my previous problem with invoking odb with the --odb-epilogue option from within CMake, I am now faced with organizing the epilogue headers. I dont remember reading anything about them, so I'll quickly write down my findings: when writing an epilogue header, you have to put in #include statements for the mapped class AND for the epilogue headers of all persistent classes referenced in the mapped class. For example, if you have classes Person and Address, like so: //person.h: class Person { shared_ptr
myaddress; } //Address.h: class Address { } The epilogue header for Project will have to have #include "person.h" #include "address_epilogue.h" This leads me to the conclusion that it might be best to lump all pragmas for the whole project into one file, and pass that as epilogue to odb for each input file.. Regards, Chris From boris at codesynthesis.com Tue Dec 16 08:23:03 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Dec 16 08:31:36 2014 Subject: [odb-users] odb-epilogue conclusions In-Reply-To: <004601d01932$72c078a0$584169e0$@gsvitec.com> References: <004601d01932$72c078a0$584169e0$@gsvitec.com> Message-ID: Hi Christian, Christian Sell writes: > I dont remember reading anything about them, [...] The various options, including the --odb-epilogue approach, are covered at the beginning of Chapter 14, "ODB Pragma Language". > so I'll quickly write down my findings: Thanks, that's appreciated. > when writing an epilogue header, you have to put in #include statements for > the mapped class AND for the epilogue headers of all persistent classes > referenced in the mapped class. > > [...] > > #include "person.h" > > #include "address_epilogue.h" For those wondering why we need to include person.h here (seeing that this file is included by the --odb-epilogue option after person.h), it is for the case where person_epilogue.h is itself #included into another *_epilogue.h file (like address_epilogue.h above). > This leads me to the conclusion that it might be best to lump all pragmas > for the whole project into one file, and pass that as epilogue to odb for > each input file.. Yes, that would work if you don't have too many persistent classes. Boris From bbourke-martin at darkfield.com Tue Dec 16 16:04:29 2014 From: bbourke-martin at darkfield.com (Bourke-Martin, Brian) Date: Tue Dec 16 16:04:38 2014 Subject: [odb-users] Startup processes Message-ID: Hello all Three related questions 1) When my app first start and runs for the first time, is there a way we can detect if the system is a virgin system? 2) I would like to use the answer from 1) to conditionally run the create_schema command. Is this a "good" way of doing this? 3) When I do create the schema, is there a way of setting up the permissions on tables (I am using sqlite and postgresql so this questions is mostly just for postgresql). Thanks in advance! -- Brian Bourke-Martin Manager of Operations and Software Dark Field Technologies 70 Robinson Boulevard Orange, CT. 06477 www.darkfield.com 203.298.0731 ext. 212 From boris at codesynthesis.com Wed Dec 17 07:04:52 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 17 07:13:25 2014 Subject: [odb-users] Startup processes In-Reply-To: References: Message-ID: Hi Brian, Bourke-Martin, Brian writes: > 1) When my app first start and runs for the first time, is there a way we > can detect if the system is a virgin system? If you turn on schema evolution support (Chapter 13, "Database Schema Evolution") then ODB will indicate this situation as schema version 0. > 2) I would like to use the answer from 1) to conditionally run the > create_schema command. Is this a "good" way of doing this? Yes, that's the recommended way to do this. In fact, there is some sample code in Section 13.2, "Schema Migration" that does exactly that. > 3) When I do create the schema, is there a way of setting up the > permissions on tables (I am using sqlite and postgresql so this > questions is mostly just for postgresql). You can execute any additional SQL statements before and/or after creating the tables with the create_schema() call using the database::execute() function (Section 3.12, "Executing Native SQL Statements"). Boris From boris at codesynthesis.com Wed Dec 17 09:55:39 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 17 10:04:22 2014 Subject: [odb-users] Polymorphic code generation problem on PostgreSQL In-Reply-To: <548EF183.6020200@infotecs.ru> References: <548AA188.4030808@infotecs.ru> <548EF183.6020200@infotecs.ru> Message-ID: <20141217145539.GA18916@codesynthesis.com> Hi Mikhail, Tomilov.Mikhail writes: > It would be nice to get binary build for i686-windows and i686-linux-gnu. Here you go: http://codesynthesis.com/~boris/tmp/odb/pre-release/a5/ Let me know if there are any issues. Boris From philip.ethier at gmail.com Thu Dec 18 17:53:36 2014 From: philip.ethier at gmail.com (Philip Ethier) Date: Thu Dec 18 22:20:28 2014 Subject: [odb-users] Failing assert in error.cxx Message-ID: Hello I'm seeing a failing assert inside odb/pgsql/error.cxx around line 50. It looks like PGresultErrorField is returning a nullptr. I can repeatedly trigger the failed assertion by using tcpkill to kill the connection to the db. Is there any way around this? If not can a bug fix be put out? Thanks, --Phil From grasmanek94 at gmail.com Fri Dec 19 04:45:04 2014 From: grasmanek94 at gmail.com (Rafal Gm) Date: Fri Dec 19 05:40:05 2014 Subject: [odb-users] How to make a exact copy of the object? Message-ID: I am using a singlethreaded application, but I made ODB process all SQL in another thread (don't worry I don't use any ODB or related things in the non-odb thread). Now, to prevent data races I need to make a exact copy of my structure (like the hello world person class). But whenever I make a copy and insert it in the other thread, the copy gets a new id() instead of the old one. How can I make a 1:1 copy of the object I have the pointer to? From bbourke-martin at darkfield.com Fri Dec 19 08:43:38 2014 From: bbourke-martin at darkfield.com (Bourke-Martin, Brian) Date: Fri Dec 19 08:43:45 2014 Subject: [odb-users] Startup processes In-Reply-To: References: Message-ID: Hi Boris, Thanks for the feedback, it's working great now! I have one followup question which I do not seem to be able to divine from the documentation. When I add the pragma line "#pragma db model version(1, 1)" to one of my data models it seems to work ok, but the documentation seems to imply that this line should be on *each* of my data models. When I try adding it to another one, I get a error stating the "schema_version" relationship already exists. So should the model version line be stated once per data table or once per schema? Thanks again! Brian On Wed, Dec 17, 2014 at 7:04 AM, Boris Kolpackov wrote: > > Hi Brian, > > Bourke-Martin, Brian writes: > > > 1) When my app first start and runs for the first time, is there a way we > > can detect if the system is a virgin system? > > If you turn on schema evolution support (Chapter 13, "Database Schema > Evolution") then ODB will indicate this situation as schema version 0. > > > > 2) I would like to use the answer from 1) to conditionally run the > > create_schema command. Is this a "good" way of doing this? > > Yes, that's the recommended way to do this. In fact, there is some > sample code in Section 13.2, "Schema Migration" that does exactly > that. > > > > 3) When I do create the schema, is there a way of setting up the > > permissions on tables (I am using sqlite and postgresql so this > > questions is mostly just for postgresql). > > You can execute any additional SQL statements before and/or after > creating the tables with the create_schema() call using the > database::execute() function (Section 3.12, "Executing Native SQL > Statements"). > > Boris > -- Brian Bourke-Martin Manager of Operations and Software Dark Field Technologies 70 Robinson Boulevard Orange, CT. 06477 www.darkfield.com 203.298.0731 ext. 212 From newzai.chen at anchormobile.com Sun Dec 21 00:25:15 2014 From: newzai.chen at anchormobile.com (newzai.chen) Date: Sun Dec 21 02:48:17 2014 Subject: [odb-users] How I can use ODB mssql on Linux Centos Message-ID: <2014122113251496859614@anchormobile.com> I had install unixODBC?freetds on my centos OS? test code? #include #include #include #include #include #include #include #include int main( int argc, char ** argv ) { //odb::mssql::database db("test","test","OpenMas6","192.168.0.44",1433,"TDS"); try{ odb::mssql::database db(argc,argv); odb::transaction t ( db.begin() ); db.execute("select * from XXX"); t.commit(); }catch( odb::mssql::database_exception & ex ){ std::cout< References: Message-ID: Hi Rafal, Rafal Gm writes: > I am using a singlethreaded application, but I made ODB process all SQL in > another thread (don't worry I don't use any ODB or related things in the > non-odb thread). Why would I be worried? ODB supports multi-threaded database access. > Now, to prevent data races I need to make a exact copy of my structure > (like the hello world person class). But whenever I make a copy and insert > it in the other thread, the copy gets a new id() instead of the old one. > How can I make a 1:1 copy of the object I have the pointer to? I don't know what "insert it in the other thread" means and since you don't show any actual code, I can only guess. And my guess is that you use auto id and when you persist the copy in the database, the database assigns it a new id. If that's the case, then the only way to avoid this behavior is to not use auto ids and instead assign them yourself. Boris From boris at codesynthesis.com Sun Dec 21 03:19:09 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Dec 21 03:15:41 2014 Subject: [odb-users] Startup processes In-Reply-To: References: Message-ID: Hi Brian, Bourke-Martin, Brian writes: > When I add the pragma line "#pragma db model version(1, 1)" to one of my > data models it seems to work ok, but the documentation seems to imply that > this line should be on *each* of my data models. Correct. I assume by "data model" you mean a header file that defines one or more persistent objects. > When I try adding it to another one, I get a error stating the > "schema_version" relationship already exists. This is because you generate the database schema into multiple .sql files and ODB places the statement for creating the schema_version table into each of them (ODB has no way of knowing that there is another .sql file that would create it). The recommended way to handle this (which also has other benefits) is to generate a combined .sql file for all of your persistent classes. Look for a paragraph that starts with "If your object model consists of a large number of header files..." in Section 13.1, "Object Model Version and Changelog". Alternatively, if you would prefer to have separate .sql files, then you will need to use the --suppress-schema-version option when generating all of them except one. Boris From boris at codesynthesis.com Sun Dec 21 03:23:56 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Dec 21 03:20:35 2014 Subject: [odb-users] How I can use ODB mssql on Linux Centos In-Reply-To: <2014122113251496859614@anchormobile.com> References: <2014122113251496859614@anchormobile.com> Message-ID: Hi, newzai.chen writes: > I had install unixODBC?freetds on my centos OS You cannot use ODB with FreeTDS. You will need to install the Microsoft Native Client driver for Linux (which, BTW, works great). See this post for more information, and especially for the update at the end on using unixODBC 2.3.0 vs 2.3.1: http://www.codesynthesis.com/~boris/blog/2011/12/02/microsoft-sql-server-odbc-driver-linux/ Boris From boris at codesynthesis.com Sun Dec 21 04:08:24 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Dec 21 04:04:59 2014 Subject: [odb-users] Failing assert in error.cxx In-Reply-To: References: Message-ID: Hi Philip, Philip Ethier writes: > I'm seeing a failing assert inside odb/pgsql/error.cxx around line 50. It > looks like PGresultErrorField is returning a nullptr. I can repeatedly > trigger the failed assertion by using tcpkill to kill the connection to the > db. Is there any way around this? If not can a bug fix be put out? It is not clear at all from the PG's documentation when PGresultErrorField() can and cannot return NULL. So we put the asserts to "learn more", so to speak. I have re-implemented the translate_error() function quite differently. Can you copy the below error.cxx file into your libodb-pgsql, rebuild it, and then let me know if everything works as expected in your tests? http://codesynthesis.com/~boris/tmp/odb/error.cxx And thanks for the report! Boris From rapp.jens at googlemail.com Sun Dec 21 12:44:46 2014 From: rapp.jens at googlemail.com (Jens Rapp) Date: Mon Dec 22 03:04:45 2014 Subject: [odb-users] odb doesn't generate sql for sqlite Message-ID: <5497070E.2010902@web.de> Hi, just downloaded odb and installed it. I installed libodb-sqlite and libodb-mysql. compiling works for both but i didn't manage to build an sql file for sqlite. Here's the class /* * person.h * * Created on: 21.12.2014 * Author: tecdroid */ #ifndef PERSON_H_ #define PERSON_H_ #include #include #pragma db object class person { private: friend class odb::access; person(); #pragma db id auto unsigned long id_; std::string name_; std::string vorname_; std::string kultur_; std::string profession_; unsigned long geburt_; public: person (std::string name, std::string vorname, std::string kultur, unsigned long geburt); virtual ~person(); unsigned long getGeburt() const; void setGeburt(unsigned long geburt); unsigned long getId() const; void setId(unsigned long id); const std::string& getKultur() const; void setKultur(const std::string& kultur); const std::string& getName() const; void setName(const std::string& name); const std::string& getProfession() const; void setProfession(const std::string& profession); const std::string& getVorname() const; void setVorname(const std::string& vorname); }; #endif /* PERSON_H_ */ Working command is odb -x "-std=c++11" -d mysql --generate-schema person.h not working command is odb -x "-std=c++11" -d sqlite --generate-schema person.h my actual workaround would be to generate schema for mysql first and alter this.. after, I'll have to re-generate the code.. Is there any way to repair this? From boris at codesynthesis.com Mon Dec 22 04:14:43 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 22 04:11:16 2014 Subject: [odb-users] odb doesn't generate sql for sqlite In-Reply-To: <5497070E.2010902@web.de> References: <5497070E.2010902@web.de> Message-ID: Hi Jens, Jens Rapp writes: > Working command is > odb -x "-std=c++11" -d mysql --generate-schema person.h Use --std=c++11 instead of -x "-std=c++11". > not working command is > odb -x "-std=c++11" -d sqlite --generate-schema person.h By default for SQLite ODB produces schema embedded into the generated C++ files rather than as a standalone .sql file. See Section 3.4, "Database" in the ODB manual for more information on this. Boris From rapp.jens at googlemail.com Mon Dec 22 05:59:16 2014 From: rapp.jens at googlemail.com (Jens Rapp) Date: Mon Dec 22 07:03:16 2014 Subject: [odb-users] odb doesn't generate sql for sqlite In-Reply-To: References: <5497070E.2010902@web.de> Message-ID: <5497F984.8040802@gmail.com> hi, this doesn't work. "unknown option" On 22.12.2014 10:14, Boris Kolpackov wrote: > Hi Jens, > > Jens Rapp writes: > >> Working command is >> odb -x "-std=c++11" -d mysql --generate-schema person.h > Use --std=c++11 instead of -x "-std=c++11". > > >> not working command is >> odb -x "-std=c++11" -d sqlite --generate-schema person.h > By default for SQLite ODB produces schema embedded into the > generated C++ files rather than as a standalone .sql file. > See Section 3.4, "Database" in the ODB manual for more > information on this. > > Boris > From boris at codesynthesis.com Mon Dec 22 07:09:58 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 22 07:10:41 2014 Subject: [odb-users] odb doesn't generate sql for sqlite In-Reply-To: <5497F984.8040802@gmail.com> References: <5497070E.2010902@web.de> <5497F984.8040802@gmail.com> Message-ID: Sorry, that should have been '--std c++11', without '='. Boris From grosr.romain at gmail.com Mon Dec 22 11:50:40 2014 From: grosr.romain at gmail.com (Romain Gros) Date: Mon Dec 22 12:35:00 2014 Subject: [odb-users] Request return different results if executed in command line In-Reply-To: References: Message-ID: Hi ! I've been doing some tests and I think I found the problem. AvailableQuestStep_idCharacter was a static thread_local variable. It seems that, when entering the ODB generated source (the access::view_traits_impl< ::AvailableQuestStep, id_mysql >::query method), my variable changed value (like if it as an other thread; I think I didn't get something here, but anyway). So I changed it to an extern thread_local variable and everything works fine ! Thanks a lot !! Best regards, Romain 2014-12-15 14:41 GMT+01:00 Boris Kolpackov : > Hi Romain, > > Romain Gros writes: > > > I am experiencing this problem on MySQL and PostgreSQL. > > If you get the same difference in behavior using both databases then > there is definitely some logical difference between the two queries > that you are running. It is very unlikely to be a bug in the runtime > or a configuration issue. > > One thing that you can do is to try to simplify the query by going > back one step at a time and see where the difference disappears (or > you get the result that you would expect). For example, remove > aggregation and see if you get the expected number of rows. > > If that doesn't help, then I would need a complete working example > that reproduces the problem. In the fragments that you have provided > I don't see anything wrong. > > > > PPS: I had another quick question, is it possible to make sub-queries in > > the where clause using ODB instead of writing pure sql in the query? > > There is no direct support yet but you should be able to write them > using the mixed style (e.g., using C++ identifier for column names, > etc). > > Boris > From philip.ethier at gmail.com Mon Dec 22 12:01:10 2014 From: philip.ethier at gmail.com (Philip Ethier) Date: Mon Dec 22 12:35:00 2014 Subject: [odb-users] Failing assert in error.cxx In-Reply-To: References: Message-ID: Hi Boris, The patch works. I can catch odb::recoverable and it shows connection lost. Thanks for putting the patch together! Are you going to release the patch or should I manage the patch on my end? Regards, --Phil On Dec 21, 2014 3:04 AM, "Boris Kolpackov" wrote: > Hi Philip, > > Philip Ethier writes: > > > I'm seeing a failing assert inside odb/pgsql/error.cxx around line 50. It > > looks like PGresultErrorField is returning a nullptr. I can repeatedly > > trigger the failed assertion by using tcpkill to kill the connection to > the > > db. Is there any way around this? If not can a bug fix be put out? > > It is not clear at all from the PG's documentation when > PGresultErrorField() > can and cannot return NULL. So we put the asserts to "learn more", so to > speak. > > I have re-implemented the translate_error() function quite differently. > Can you copy the below error.cxx file into your libodb-pgsql, rebuild > it, and then let me know if everything works as expected in your tests? > > http://codesynthesis.com/~boris/tmp/odb/error.cxx > > And thanks for the report! > > Boris > From boris at codesynthesis.com Tue Dec 23 03:25:27 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Dec 23 03:22:10 2014 Subject: [odb-users] Failing assert in error.cxx In-Reply-To: References: Message-ID: Hi Philip, Philip Ethier writes: > The patch works. I can catch odb::recoverable and it shows connection lost. Great, thanks for testing it. > Are you going to release the patch or should I manage the patch on my end? I can make a bug-fix release for libodb-pgsql if that helps. Otherwise, the next version of ODB is to be released in January and will include the fix. Boris From picserez at gmail.com Tue Dec 23 08:22:25 2014 From: picserez at gmail.com (Erez Pics) Date: Tue Dec 23 08:28:13 2014 Subject: [odb-users] Persisting objects after ID change Message-ID: Hi Boris, Following what I wrote before regarding temp identifiers, ODB works GREAT with negative value IDs, however it fails updating the new ID. I am testing that the new identifier is changed properly on the main object and on it's child records. I have defined ON UPDATE CASCADE on the FK in the schema on the child records and created an inverse relationship between my ODB object and it's child records. The flow: I have an ODB object that has been persisted before with a temp identifier, I set a new value to it's identity field and call data_base->update(object), the result "object not persistent" exception, ODB refuses to update an existing object to use the new identifier. If I call data_base->persist(object) it succeeds however a NEW record is created, the child records are updated properly when saved and point to the new record but I am left with the old object in the DB so other FK records still point to the old object. Can you please advice how to resolve this problem ? Thank you very very much for you help, Erez. From philip.ethier at gmail.com Tue Dec 23 13:49:54 2014 From: philip.ethier at gmail.com (Philip Ethier) Date: Wed Dec 24 07:10:18 2014 Subject: [odb-users] Failing assert in error.cxx In-Reply-To: References: Message-ID: If the release is schedule for early January I can wait. But if the end I would like a bug fix release. Thanks so much, --Phil On Dec 23, 2014 2:22 AM, "Boris Kolpackov" wrote: > Hi Philip, > > Philip Ethier writes: > > > The patch works. I can catch odb::recoverable and it shows connection > lost. > > Great, thanks for testing it. > > > > Are you going to release the patch or should I manage the patch on my > end? > > I can make a bug-fix release for libodb-pgsql if that helps. Otherwise, > the next version of ODB is to be released in January and will include the > fix. > > Boris > From lg.cookies at outlook.com Sun Dec 28 22:02:05 2014 From: lg.cookies at outlook.com (lg admin) Date: Sun Dec 28 22:02:18 2014 Subject: [odb-users] COLLATE binary not existed in postgresql Message-ID: 49 #pragma db key_options("COLLATE binary") 50 std::map properties_; It seems that COLLATE binary does not existed in postgresql. What would I do in postgresl for this use case? From christian at gsvitec.com Mon Dec 29 13:54:54 2014 From: christian at gsvitec.com (Christian Sell) Date: Mon Dec 29 13:54:57 2014 Subject: [odb-users] let class members default to transient Message-ID: <123392944.425877.1419879294466.JavaMail.open-xchange@omgreatgod.store> Hello, I have several classes which contain only a few members that are mapped to the database, while most members are transient only. Now I am looking for a way to tell the compiler to only consider those members that are explcitly mapped through member pragmas, and leave the others alone. Currently, it seems like I have to put a "#pragma transient" alongside each of the non-mapped members. I tried "db object(myclass) transient", but that seems to cause the compiler to even ignore the explicitly mapped members.. thanks, Christian From christian at gsvitec.com Mon Dec 29 15:17:28 2014 From: christian at gsvitec.com (Christian Sell) Date: Mon Dec 29 15:17:32 2014 Subject: [odb-users] Problem generating and compiling with pragma-only file Message-ID: <1901022251.431381.1419884249037.JavaMail.open-xchange@omgreatgod.store> Hello, I have a problem with an application which has all ODB pragmas in a separate pragma-only header file. The pragma file is named "application_pragmas.h" and conceptually looks like this: #include "application.h" #pragma db object(Someclass) #pragma db member(Settings::num) id auto and the "application.h" header holds the class definitions (among other things): #include class Someclass { friend class odb::access; int num; } Now, the odb command generates 3 files as expected, namely: application_pragmas_odb.cpp application_pragmas_odb.h application_pragmas_odb_inline.h unfortunately, the generated file "application_pragmas_odb.h" contains the following include statement: #include "flexisapplication_odb.h" which references a file wich DID NOT get generated, although it obviously follows the naming pattern for odb-generated files. Moreover, if I remove the include statement, the compile goes through without problems. what is going wrong? thanks, Christian From christian at gsvitec.com Tue Dec 30 05:08:27 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 30 05:08:30 2014 Subject: [odb-users] Problem generating and compiling with pragma-only file In-Reply-To: <1901022251.431381.1419884249037.JavaMail.open-xchange@omgreatgod.store> References: <1901022251.431381.1419884249037.JavaMail.open-xchange@omgreatgod.store> Message-ID: <1061662679.464749.1419934107654.JavaMail.open-xchange@omgreatgod.store> answering to myself: that is what one gets by directly passing the pragma-only file to the odb compiler, rather than directly passing in the file with the classdefs and passing the pragma file via -odb-epilogue-file (as described in the docs) regards, Chris > Christian Sell hat am 29. Dezember 2014 um 21:17 > geschrieben: > > > Hello, > > I have a problem with an application which has all ODB pragmas in a separate > pragma-only header file. The pragma file is named "application_pragmas.h" and > conceptually looks like this: > > #include "application.h" > #pragma db object(Someclass) > #pragma db member(Settings::num) id auto > > and the "application.h" header holds the class definitions (among other > things): > > #include > > class Someclass { > friend class odb::access; > > int num; > } > > Now, the odb command generates 3 files as expected, namely: > > application_pragmas_odb.cpp > application_pragmas_odb.h > application_pragmas_odb_inline.h > > unfortunately, the generated file "application_pragmas_odb.h" contains the > following include statement: > > #include "flexisapplication_odb.h" > > which references a file wich DID NOT get generated, although it obviously > follows the naming pattern for odb-generated files. Moreover, if I remove the > include statement, the compile goes through without problems. > > what is going wrong? > > thanks, > Christian > From boris at codesynthesis.com Tue Dec 30 08:40:42 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Dec 30 08:37:10 2014 Subject: [odb-users] Persisting objects after ID change In-Reply-To: References: Message-ID: Hi Erez, Erez Pics writes: > The flow: I have an ODB object that has been persisted before with a > temp identifier, I set a new value to it's identity field and call > data_base->update(object), the result "object not persistent" > exception, ODB refuses to update an existing object to use the new > identifier. The whole ODB architecture assumes that object identifiers are immutable. In fact, conceptually, saying something like "I set a new value to it's identity field" doesn't make sense since if you change the object's identity, it is no longer the same object. Or, to put it in more technical terms, when you call update(), underneath, ODB executes "UPDATE ... WHERE id = ?" with the value for id coming from the object identifier member. But, since its value you have changed, ODB will not be able to find the original row in the database. This is why in my original reply to your idea of using negative id values to indicate a special object state I suggested that a separate flag might be a cleaner solution. But, if you still want to update the object id, there is a way, not a very elegant one, though. The idea is to map another special class to the same table that would allow you to change the id. Here is an outline: #pragma db object table("my_object") class my_object // You original object. { ... #pragma db id column("id") unsigned int id; }; #pragma db object table("my_object") struct my_object_id { my_object_id (unsigned int o, unsigned int n): old_id (o), new_id (n) {} #pragma db id column("id") unsigned int old_id; #pragma db column("id") unsigned int new_id; }; my_object o = ...; db.update (my_object_id (o.id, -o.id)); Note that my_object_id should come after my_object in the header file in order to get the correct table definition in the generated schema. Boris From boris at codesynthesis.com Tue Dec 30 08:50:39 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Dec 30 08:47:06 2014 Subject: [odb-users] let class members default to transient In-Reply-To: <123392944.425877.1419879294466.JavaMail.open-xchange@omgreatgod.store> References: <123392944.425877.1419879294466.JavaMail.open-xchange@omgreatgod.store> Message-ID: Hi Christian, Christian Sell writes: > I have several classes which contain only a few members that are > mapped to the database, while most members are transient only. Now > I am looking for a way to tell the compiler to only consider those > members that are explcitly mapped through member pragmas, and leave > the others alone. Currently, it seems like I have to put a "#pragma > transient" alongside each of the non-mapped members. > > I tried "db object(myclass) transient", but that seems to cause the > compiler to even ignore the explicitly mapped members.. Yes, you almost got to the solution. The last step in achieving what you want is to define virtual data members for the ones that are persistent: #pragma db object transient struct my_object { ... // Lots more data members that we don't want in the database. unsigned int id_; std::string str_; }; #pragma db member(my_object::id) virtual(unsigned int) access(id_) id auto #pragma db member(my_object::str) virtual(std::string) access(str_) This mechanism is described in more detail in Section 14.4.13, "virtual". Boris From boris at codesynthesis.com Tue Dec 30 09:04:16 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Dec 30 09:00:44 2014 Subject: [odb-users] Problem generating and compiling with pragma-only file In-Reply-To: <1061662679.464749.1419934107654.JavaMail.open-xchange@omgreatgod.store> References: <1901022251.431381.1419884249037.JavaMail.open-xchange@omgreatgod.store> <1061662679.464749.1419934107654.JavaMail.open-xchange@omgreatgod.store> Message-ID: Hi Christian, Christian Sell writes: > that is what one gets by directly passing the pragma-only file to the odb > compiler, rather than directly passing in the file with the classdefs and > passing the pragma file via -odb-epilogue-file (as described in the docs) Note that ODB has a mechanism for changing the place (as in the header) where it "thinks" a class is defined so it should be possible to compile the "mapping" file and get a sensible result if you that's what you want. This is described in more detail in the "Custom C++ to Database Type Mapping" blog post, the "Composite Value Types" section (the post uses it to handle a composite value type but it works equally well for objects): http://www.codesynthesis.com/~boris/blog/2012/10/16/custom-cxx-to-database-type-mapping-in-odb/ Boris From boris at codesynthesis.com Tue Dec 30 09:19:06 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Dec 30 09:15:34 2014 Subject: [odb-users] COLLATE binary not existed in postgresql In-Reply-To: References: Message-ID: Hi, lg admin writes: > 49 #pragma db key_options("COLLATE binary") 50 std::map properties_; > > It seems that COLLATE binary does not existed in postgresql. What would > I do in postgresl for this use case? This is really a question about PostgreSQL specifically and not ODB. As a result, it would be better to ask such questions on PostgreSQL-specific mailing lists/forums/etc; you will probably get a better and faster answer this way. Having said that, a quick search brought this page: http://stackoverflow.com/questions/7778714/postgresql-utf-8-binary-collation Which indicates that the PG equivalent would be COLLATE "C" or COLLATE "POSIX": #pragma db key_options("COLLATE \"C\"") It also points to the relevant Postgres documentation. Boris From christian at gsvitec.com Tue Dec 30 20:49:33 2014 From: christian at gsvitec.com (Christian Sell) Date: Tue Dec 30 20:49:36 2014 Subject: [odb-users] how to determine whether tables already exist? Message-ID: <21587641.541234.1419990573765.JavaMail.open-xchange@omgreatgod.store> Hello, I need to determine in my application whether database creation has already been executed, and if not, create it (on demand, so to speak). I thought this would be the easiest of all things, but am finally forced to resort to this list. What I want is something like if(!odb::schema_catalog::exists(*db, "nyschema")) { odb::transaction t(c->begin()); odb::schema_catalog::create_schema(*db, "myschema", false); t.commit(); } However, the call to exists() seems to check the existence of the schema mapping code, not the existence of the schema in the database (always returns true for me). How can I perform the described check? thanks, Chris From picserez at gmail.com Tue Dec 30 12:42:39 2014 From: picserez at gmail.com (Erez Pics) Date: Wed Dec 31 04:54:24 2014 Subject: [odb-users] Persisting objects after ID change In-Reply-To: References: Message-ID: Hi Boris, Thank you for your reply, your are right, with regards to the object id being immutable, this is a very special behavior we need. This is not the main flow of our framework, however we need the temp identifiers to change to permanent ones seamlessly and once made permanent the ODB objects need to work regularly. I thought that ODB behaves in a similar way regarding the update query, to solve it I execute a small update query that directly changes the object id and then I change the object id in the ODB object, now that the new id is persisted it seems ODB behaves great and all update operations afterwards work :-) Do you think that there is a problem with my update query and ODB using the new object id after the change ? Thank you and Happy New Year, Erez. On Tue, Dec 30, 2014 at 3:40 PM, Boris Kolpackov wrote: > Hi Erez, > > Erez Pics writes: > >> The flow: I have an ODB object that has been persisted before with a >> temp identifier, I set a new value to it's identity field and call >> data_base->update(object), the result "object not persistent" >> exception, ODB refuses to update an existing object to use the new >> identifier. > > The whole ODB architecture assumes that object identifiers are > immutable. In fact, conceptually, saying something like "I set > a new value to it's identity field" doesn't make sense since > if you change the object's identity, it is no longer the same > object. Or, to put it in more technical terms, when you call > update(), underneath, ODB executes "UPDATE ... WHERE id = ?" > with the value for id coming from the object identifier member. > But, since its value you have changed, ODB will not be able to > find the original row in the database. > > This is why in my original reply to your idea of using negative > id values to indicate a special object state I suggested that > a separate flag might be a cleaner solution. > > But, if you still want to update the object id, there is a way, > not a very elegant one, though. The idea is to map another special > class to the same table that would allow you to change the id. > Here is an outline: > > #pragma db object table("my_object") > class my_object // You original object. > { > ... > > #pragma db id column("id") > unsigned int id; > }; > > #pragma db object table("my_object") > struct my_object_id > { > my_object_id (unsigned int o, unsigned int n): old_id (o), new_id (n) {} > > #pragma db id column("id") > unsigned int old_id; > > #pragma db column("id") > unsigned int new_id; > }; > > my_object o = ...; > > db.update (my_object_id (o.id, -o.id)); > > Note that my_object_id should come after my_object in the header file > in order to get the correct table definition in the generated schema. > > Boris From harriev9 at gmail.com Wed Dec 31 08:34:44 2014 From: harriev9 at gmail.com (Harrie9) Date: Wed Dec 31 08:34:53 2014 Subject: [odb-users] How to transfer query results between methods. Message-ID: <1420032884.6434.4.camel@gmail.com> Hello, I am having the next code fragment (method): odb::result relationManager::getRelations() { typedef odb::query query; typedef odb::result result; // Show action { transaction t (db->begin ()); result r (db->query ()); qDebug() << "Number of rows fetched" << r.size(); t.commit (); return r; } } This method fetches relation information from the database. It works (the debug log show 34 row). However the calling method show the number of rows is zero. I expect the information is lost due to destruction of the r object. My question is: how should I pass this information between method calls? Greetings, Harrie From boris at codesynthesis.com Wed Dec 31 12:34:57 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 31 12:31:47 2014 Subject: [odb-users] how to determine whether tables already exist? In-Reply-To: <21587641.541234.1419990573765.JavaMail.open-xchange@omgreatgod.store> References: <21587641.541234.1419990573765.JavaMail.open-xchange@omgreatgod.store> Message-ID: Hi Christian, Christian Sell writes: > I need to determine in my application whether database creation has > already been executed, and if not, create it (on demand, so to speak). Here is a thread on this topic from a couple of week ago: http://www.codesynthesis.com/pipermail/odb-users/2014-December/002283.html Boris From boris at codesynthesis.com Wed Dec 31 12:39:11 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 31 12:35:38 2014 Subject: [odb-users] Persisting objects after ID change In-Reply-To: References: Message-ID: Hi Erez, Erez Pics writes: > Do you think that there is a problem with my update query and ODB > using the new object id after the change ? There is nothing wrong with executing a custom UPDATE statement. One advantage of my method, however, is that it uses prepared statements and therefore could be more efficient. Also, you will need to think about other ODB facilities that may mis-function (or need adjustment) after the id change. One that comes to mind off the top of my head is the object cache, if you are using it. Boris From boris at codesynthesis.com Wed Dec 31 12:42:29 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 31 12:38:52 2014 Subject: [odb-users] How to transfer query results between methods. In-Reply-To: <1420032884.6434.4.camel@gmail.com> References: <1420032884.6434.4.camel@gmail.com> Message-ID: Hi Harrie, Harrie9 writes: > I expect the information is lost due to destruction of the r object. No, the problem is not the destruction of the result object but the end of the transaction. You cannot iterate over the query result outside of a transaction. So you will either need to factor out the transaction begin/commit calls to the caller or you will have to iterate in the function and make some kind of a copy of the result sequence. Boris