From isn at extrn.org Tue Jul 1 04:42:02 2014 From: isn at extrn.org (Stanislav Ivochkin) Date: Tue Jul 1 05:04:48 2014 Subject: [odb-users] ODB compiler does not handle UTF-8 with BOM properly Message-ID: When running ODB compiler on UTF-8 with BOM encoded headers it reports errors: file.h:1:1: error: stray ?\357? in program file.h:1:1: error: stray ?\273? in program file.h:1:1: error: stray ?\277? in program Note that the same error is reported by some versions of gcc that lack BOM support. I am using binary ODB Compiler v.2.3.0 running on Ubuntu 12.04 i386. The windows version seems to be affected too. Due to some VS limitations of handling utf8, I can not convert sources to BOM-free utf8. Any ideas for workarounds? -- Regards, Stas. From boris at codesynthesis.com Tue Jul 1 05:20:05 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Jul 1 05:24:52 2014 Subject: [odb-users] ODB compiler does not handle UTF-8 with BOM properly In-Reply-To: References: Message-ID: Stanislav Ivochkin writes: > When running ODB compiler on UTF-8 with BOM encoded headers it reports > errors: > > file.h:1:1: error: stray ?\357? in program > file.h:1:1: error: stray ?\273? in program > file.h:1:1: error: stray ?\277? in program > > Note that the same error is reported by some versions of gcc that lack BOM > support. I did some searching and apparently BOM support was added to GCC around 2008. So any version of GCC that is used by ODB should support this. I also found this page which suggest the problem is not the BOM: http://stackoverflow.com/questions/7899795/is-it-possible-to-get-gcc-to-compile-utf-8-with-bom-source-files Boris From isn at extrn.org Tue Jul 1 06:26:13 2014 From: isn at extrn.org (Stanislav Ivochkin) Date: Tue Jul 1 06:56:52 2014 Subject: [odb-users] ODB compiler does not handle UTF-8 with BOM properly In-Reply-To: References: Message-ID: 2014-07-01 13:20 GMT+04:00 Boris Kolpackov : > Stanislav Ivochkin writes: > > > When running ODB compiler on UTF-8 with BOM encoded headers it reports > > errors: > > > > file.h:1:1: error: stray ?\357? in program > > file.h:1:1: error: stray ?\273? in program > > file.h:1:1: error: stray ?\277? in program > > > > Note that the same error is reported by some versions of gcc that lack > BOM > > support. > > I did some searching and apparently BOM support was added to GCC around > 2008. So any version of GCC that is used by ODB should support this. > Inside ODB 2.3.0 binary distribution there is gcc 4.7.3. I have 4.8.1 and 4.6.4 installed. All of them support UTF-8. And according to strace, gcc 4.7.3 shipped with ODB Compiler is invoked. I also found this page which suggest the problem is not the BOM I think the problem is exactly with BOM. See explanation details below. [isn@ivochkin /tmp/odb]$ cat type_map.bom.h #pragma db map type("date") as("INTEGER") [isn@ivochkin /tmp/odb]$ hexdump -C type_map.bom.h 00000000 ef bb bf 23 70 72 61 67 6d 61 20 64 62 20 6d 61 |...#pragma db ma| 00000010 70 20 74 79 70 65 28 22 64 61 74 65 22 29 20 61 |p type("date") a| 00000020 73 28 22 49 4e 54 45 47 45 52 22 29 0a |s("INTEGER").| 0000002d [isn@ivochkin /tmp/odb]$ hexdump -C type_map.nobom.h 00000000 23 70 72 61 67 6d 61 20 64 62 20 6d 61 70 20 74 |#pragma db map t| 00000010 79 70 65 28 22 64 61 74 65 22 29 20 61 73 28 22 |ype("date") as("| 00000020 49 4e 54 45 47 45 52 22 29 0a |INTEGER").| 0000002a [isn@ivochkin /tmp/odb]$ $ODB_COMPILER --version ODB object-relational mapping (ORM) compiler for C++ 2.3.0 Copyright (c) 2009-2013 Code Synthesis Tools CC This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [isn@ivochkin /tmp/odb]$ $ODB_COMPILER --database pgsql type_map.nobom.h [isn@ivochkin /tmp/odb]$ $ODB_COMPILER --database pgsql type_map.bom.h type_map.bom.h:1:1: error: stray ?\357? in program type_map.bom.h:1:1: error: stray ?\273? in program type_map.bom.h:1:1: error: stray ?\277? in program type_map.bom.h:1:1: error: stray ?#? in program type_map.bom.h:1:5: error: ?pragma? does not name a type I have attached minimal reproducible sample. -- Regards, Stas. -------------- next part -------------- A non-text attachment was scrubbed... Name: type_map.bom.h Type: text/x-chdr Size: 44 bytes Desc: not available Url : http://codesynthesis.com/pipermail/odb-users/attachments/20140701/417a15cf/type_map.bom.h From boris at codesynthesis.com Wed Jul 2 06:38:14 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 2 06:43:02 2014 Subject: [odb-users] ODB compiler does not handle UTF-8 with BOM properly In-Reply-To: References: Message-ID: Hi Stanislav, Stanislav Ivochkin writes: > I have attached minimal reproducible sample. Thanks for the test case. I figured it out and indeed the problem was in the ODB compiler. I have also committed the fix: http://scm.codesynthesis.com/?p=odb/odb.git;a=commit;h=fd3f1c89d75950c3603661a7255866d680ec5033 Boris From mike.ruffing at ipconfigure.com Wed Jul 2 09:53:02 2014 From: mike.ruffing at ipconfigure.com (Mike Ruffing) Date: Wed Jul 2 10:41:15 2014 Subject: [odb-users] PostgreSQL BIGINT Storage Value Message-ID: <1404309184888.94239@ipconfigure.com> Boris, Operating System: Ubuntu 14.04 LTS ODB: 2.3.0 PostgreSQL: 9.3 I am using a custom mapping that converts a posix_time::ptime and posix_time::time_duration to a long long. The long long value is mapped to PosgreSQL's BIGINT type. Using print statements I verified I am getting the correct conversion values (long long) in the "set_image" and "set_value" methods. However the values stored in the PostgreSQL database do not match. Monitoring the PostgreSQL log files I verified the incorrect values (representation) are being inserted into the database. Since "set_value" is getting the correct "long long" value I'm guessing that the values stored in the database are related to the original value. Could this be a bit shift or endianness issue? Note: I am not seeing this issue using SQLite. Here is an example of the converted value ("set_image") and final value (via pgsql log) inserted into the database: 1404308405507732 -7757826360135056384 Thanks, Mike Ruffing From boris at codesynthesis.com Wed Jul 2 10:42:51 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 2 10:47:38 2014 Subject: [odb-users] PostgreSQL BIGINT Storage Value In-Reply-To: <1404309184888.94239@ipconfigure.com> References: <1404309184888.94239@ipconfigure.com> Message-ID: Hi Mike, Mike Ruffing writes: > Could this be a bit shift or endianness issue? Yes, that's the most likely cause. PG want it in big-endian. You can use: #include odb::pgsql::details::endian_traits::ntoh() odb::pgsql::details::endian_traits::hton() See odb/pgsql/traits.hxx lines 356-397 for how standard integers are handled using these functions. Boris From mike.ruffing at ipconfigure.com Wed Jul 2 13:06:58 2014 From: mike.ruffing at ipconfigure.com (Mike Ruffing) Date: Thu Jul 3 04:12:56 2014 Subject: [odb-users] PostgreSQL BIGINT Storage Value In-Reply-To: References: <1404309184888.94239@ipconfigure.com>, Message-ID: <1404320820790.42779@ipconfigure.com> Boris, Endianness was the issue. Using hton and ntoh fixed the issue. Thanks for the help. Mike ________________________________________ From: Boris Kolpackov Sent: Wednesday, July 02, 2014 10:42 AM To: Mike Ruffing Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] PostgreSQL BIGINT Storage Value Hi Mike, Mike Ruffing writes: > Could this be a bit shift or endianness issue? Yes, that's the most likely cause. PG want it in big-endian. You can use: #include odb::pgsql::details::endian_traits::ntoh() odb::pgsql::details::endian_traits::hton() See odb/pgsql/traits.hxx lines 356-397 for how standard integers are handled using these functions. Boris From demianov314 at yandex.ru Tue Jul 8 10:29:11 2014 From: demianov314 at yandex.ru (=?koi8-r?B?5dfHxc7JyiDkxc3Y0c7P1w==?=) Date: Tue Jul 8 10:29:39 2014 Subject: [odb-users] (no subject) Message-ID: <6275181404829751@web13g.yandex.ru> I using odb-3.2.0 with Microsoft SQL Server. I try to execute stored procedure using the folowing statement #pragma db view struct ProcResult { int Result; std::string Comment; }; // . // . // . std::stringstream raw_query; raw_query << "exec Procedure" << value1 << ", " << value2 ; Result r ( db.query ( raw_query.str().c_str() ) ) ; But libodb-mssql-3.2.0 library automatically prepends "WHERE " keyword before native SQL string. I temporary solved this problem by modifying function check_prefix in file query.cxx. I added conditions s.compare (0, (n = 4), "EXEC") == 0 ||s.compare (0, (n = 4), "exec") == 0. Is there any solution to call stored procedure without modifying the source code of ODB library? From davejohansen at gmail.com Tue Jul 8 11:49:15 2014 From: davejohansen at gmail.com (Dave Johansen) Date: Tue Jul 8 11:49:22 2014 Subject: [odb-users] dates and times in sqlite3 In-Reply-To: References: Message-ID: On Thu, Jun 12, 2014 at 3:08 AM, Boris Kolpackov wrote: > Hi, > > MM writes: > > > By default, *date* converts to extended iso string like so YYYY-MM-DD, > > and *time_duration* converts to HH:MM:SS.fffffffff were fff is fractional > > seconds that are only included if non-zero. > > > > For both, the default column type is TEXT. > > Yes, SQLite does not have date-time data types. These representations, > however, are pretty standard. See this page, for example: > > http://www.sqlite.org/lang_datefunc.html > > > > 1. for date, is this compatible with the default pysqlite3 converter for > > datetime.date? > > Maybe someone else on the mailing list will be able to answer this, > but generally, this mailing list is a wrong place to ask what a Python > default converter might do. The relevant Python mailing list would be a > much more sensible place. > > Boris > > I'm probably a little late to this conversation and don't know if a change like this is even possible in the ODB codebase, but all the uses of sqlite that I've worked with store date/time in Julian Day/Date format ( http://en.wikipedia.org/wiki/Julian_day ) so that it's smaller and easier to work with (- and + just work and have intuitive results). sqlite3 also knows how to convert to/from Julian Day/Date and string formats ( http://www.sqlite.org/lang_datefunc.html ). From boris at codesynthesis.com Wed Jul 9 07:17:58 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 9 07:22:58 2014 Subject: [odb-users] (no subject) In-Reply-To: <6275181404829751@web13g.yandex.ru> References: <6275181404829751@web13g.yandex.ru> Message-ID: Hi, ??????? ???????? writes: > I using odb-3.2.0 with Microsoft SQL Server. I try to execute stored > procedure using the folowing statement > > #pragma db view > struct ProcResult > { > int Result; > std::string Comment; > }; > > std::stringstream raw_query; > raw_query << "exec Procedure" << value1 << ", " << value2 ; > > Result r ( db.query ( > raw_query.str().c_str() ) ) ; > > But libodb-mssql-3.2.0 library automatically prepends "WHERE " keyword > before native SQL string. Try this: #pragma db view query ("EXEC Procedure (?)") struct ProcResult { int Result; std::string Comment; }; typedef odb::query ProcQuery; Result r (db.query ( ProcQuery::_val (value1) + "," + ProcQuery::_val (value2))); > I temporary solved this problem by modifying function check_prefix in > file query.cxx. I added conditions > s.compare (0, (n = 4), "EXEC") == 0 || s.compare (0, (n = 4), "exec") == 0. I've added this change for the next release so that you will be able to supply the EXEC statement for the native view at runtime. Boris From abellina at gmail.com Thu Jul 10 16:14:05 2014 From: abellina at gmail.com (Alessandro Bellina) Date: Thu Jul 10 16:14:15 2014 Subject: [odb-users] Postgres error: 42P05 prepared statement already exists Message-ID: Hello I'm using odb with Postgres. I get and error trying to insert into one of my tables. The error is: 42P05 prepared statement "my_table_persist" already exists. Has anyone run into this? There's nothing special about this table or object that I can think of, other inserts work just fine. The prepared statement is large, the real name is much longer (73 characters long). Thanks, Alessandro From boris at codesynthesis.com Fri Jul 11 03:44:37 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 11 03:49:35 2014 Subject: [odb-users] Postgres error: 42P05 prepared statement already exists In-Reply-To: References: Message-ID: Hi Alessandro, Alessandro Bellina writes: > I'm using odb with Postgres. I get and error trying to insert into one > of my tables. The error is: 42P05 prepared statement "my_table_persist" > already exists. This would be mean that another statement with the same name has already been prepared on the connection. Try to search all your ODB-generated files for this name. Perhaps there is another table with the same name used elsewhere (the statement name is derived from the table name)? Boris From boris at codesynthesis.com Fri Jul 11 04:04:06 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 11 04:09:04 2014 Subject: [odb-users] dates and times in sqlite3 In-Reply-To: References: Message-ID: Hi Dave, Dave Johansen writes: > I'm probably a little late to this conversation and don't know if a change > like this is even possible in the ODB codebase, but all the uses of sqlite > that I've worked with store date/time in Julian Day/Date format ( > http://en.wikipedia.org/wiki/Julian_day ) so that it's smaller and easier > to work with (- and + just work and have intuitive results). sqlite3 also > knows how to convert to/from Julian Day/Date and string formats ( > http://www.sqlite.org/lang_datefunc.html ). Thanks for the info. Currently, the ODB profiles (Boost, Qt) support storing date/time types as either text (the ISO format, default) or integer (UNIX time, needs to be requested explicitly). See Section 23.5.2 for the Boost profile and 24.4.2 for the Qt profile. It is also possible to add support for Julian at the application level by simply implementing the traits (and I assume mapping to the FLOAT database type), just like the profiles do. Whether it is worth adding this code into the profiles themselves, I am not sure. You are the first person who mentioned any desire for this. Boris From zju3080103798 at 163.com Fri Jul 11 05:28:52 2014 From: zju3080103798 at 163.com (=?GBK?B?y++wsg==?=) Date: Fri Jul 11 05:34:03 2014 Subject: [odb-users] need help Message-ID: <3c8fa089.10e3f.14724c0fb1e.Coremail.zju3080103798@163.com> I'm a user from china.I meet some problem when i use libodb. Here is the compile error: g++ -g -DLINUX -std=gnu++11 -Wno-unknown-pragmas -Wno-deprecated -I. -I./libev ent -I./libevent/include -I./protobuf/src -I./Common -I./Controller -I./log4cplu s-1.1.3-rc2/include -I./jsoncpp-src-0.5.0/include/ -I./OdbOutput/ ./main.o ./Co mmon/ProtoMsg.pb.o ./Common/CLogger.o ./Common/person.o ./Common/SocketClient.o ./Common/SocketEvent.o ./Common/SocketServerBase.o ./Common/SocketUser.o ./Commo n/SocketUserManager.o ./Common/TestClient.o ./Common/TestServer.o ./Common/TestT CPTask.o ./Common/Util.o ./Common/zMNetService.o ./Common/zService.o ./Common/zT CPTask.o ./Common/zTCPTaskPool.o ./Common/zThread.o ./Common/person-odb.o ./Cont roller/CustomDatabase.o ./Controller/GameServer.o ./Controller/GameUser.o ./Cont roller/OdbTemplate.o ./Controller/OdbUtil.o ./Controller/ProtoMsgHandle.o ./OdbO utput//Game-schema.o ./OdbOutput//ServerList-odb.o -lpthread -levent -lprotobuf -lmysqlcppconn -llog4cplus -ljson -lodb-mysql -lodb -o MyFrame ./Controller/OdbUtil.o: In function `void odb::schema_catalog::data_migration_fu nction<2ull, 1ull>(odb::database_id, std::function, std:: string const&)': /usr/local/include/odb/schema-catalog.hxx:130: undefined reference to `odb::sche ma_catalog::data_migration_function(odb::database_id, unsigned long long, std::f unction, std::string const&)' collect2: error: ld returned 1 exit status make: *** [MyFrame] Error 1 Here is the source: static void migrate_gender (odb::database& db) { DEBUG_MSG("migrate gender!"); odb::transaction t (db.begin ()); ServerList server; db.persist(server); t.commit (); } odb::transaction t(m_db->begin()); odb::schema_catalog::data_migration_function<2,1>(*m_db,migrate_gender); odb::schema_catalog::migrate(*m_db); t.commit(); I have troubled in this problem two days ,can you help me to solve this? From abellina at gmail.com Fri Jul 11 06:07:11 2014 From: abellina at gmail.com (Alessandro Bellina) Date: Fri Jul 11 06:07:19 2014 Subject: [odb-users] Postgres error: 42P05 prepared statement already exists In-Reply-To: References: Message-ID: <583D383D-6322-4CF3-A8CC-B9E71CC08C0E@gmail.com> Thanks Boris I don't have another table with the same name (this is all under the same Schema too). One thing I forgot to mention is that if I go to Postgres and attempt to deallocate the statement manually I get a notice, that the statement name is too long and that it will be truncated. Thanks again Boris Alessandro Alessandro A. Bellina abellina@gmail.com > On Jul 11, 2014, at 2:44 AM, Boris Kolpackov wrote: > > Hi Alessandro, > > Alessandro Bellina writes: > >> I'm using odb with Postgres. I get and error trying to insert into one >> of my tables. The error is: 42P05 prepared statement "my_table_persist" >> already exists. > > This would be mean that another statement with the same name has already > been prepared on the connection. Try to search all your ODB-generated > files for this name. Perhaps there is another table with the same name > used elsewhere (the statement name is derived from the table name)? > > Boris From boris at codesynthesis.com Fri Jul 11 06:08:33 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 11 06:13:39 2014 Subject: [odb-users] need help In-Reply-To: <3c8fa089.10e3f.14724c0fb1e.Coremail.zju3080103798@163.com> References: <3c8fa089.10e3f.14724c0fb1e.Coremail.zju3080103798@163.com> Message-ID: Hi, ?? writes: > /usr/local/include/odb/schema-catalog.hxx:130: undefined reference to > `odb::schema_catalog::data_migration_function(odb::database_id, > unsigned long long, std::function, > std::string const&)' I am pretty sure the problem is with your libodb build. Currently you need to build this library in the C++11 mode since you are using C++11: ./configure CXXFLAGS=-std=gnu++11 This is something that I am planning to address in the near future. Boris From boris at codesynthesis.com Fri Jul 11 06:15:39 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 11 06:20:44 2014 Subject: [odb-users] Postgres error: 42P05 prepared statement already exists In-Reply-To: <583D383D-6322-4CF3-A8CC-B9E71CC08C0E@gmail.com> References: <583D383D-6322-4CF3-A8CC-B9E71CC08C0E@gmail.com> Message-ID: Hi Alessandro, Alessandro Bellina writes: > One thing I forgot to mention is that if I go to Postgres and attempt > to deallocate the statement manually I get a notice, that the statement > name is too long and that it will be truncated. Ah, that's definitely something worth mentioning! Now it makes sense. What most likely happens is that the names get truncated and are no longer unique. The only way I can think of to resolve this would be to shorten the table names so that the generated statement names don't get truncated. Maybe there is also a way to increase the statement name in Postgres. Boris From zju3080103798 at 163.com Fri Jul 11 06:21:02 2014 From: zju3080103798 at 163.com (=?utf-8?B?5a2Z5a6J?=) Date: Fri Jul 11 06:21:58 2014 Subject: [odb-users] need help In-Reply-To: References: <3c8fa089.10e3f.14724c0fb1e.Coremail.zju3080103798@163.com> Message-ID: <60c4a347.11fe9.14724f0bc3d.Coremail.zju3080103798@163.com> I solved the problem as you said .Thanks very much! At 2014-07-11 06:08:33, "Boris Kolpackov" wrote: >Hi, > >?? writes: > >> /usr/local/include/odb/schema-catalog.hxx:130: undefined reference to >> `odb::schema_catalog::data_migration_function(odb::database_id, >> unsigned long long, std::function, >> std::string const&)' > >I am pretty sure the problem is with your libodb build. Currently you >need to build this library in the C++11 mode since you are using C++11: > >./configure CXXFLAGS=-std=gnu++11 > >This is something that I am planning to address in the near future. > >Boris From abellina at gmail.com Fri Jul 11 06:47:28 2014 From: abellina at gmail.com (Alessandro Bellina) Date: Fri Jul 11 06:47:40 2014 Subject: [odb-users] Postgres error: 42P05 prepared statement already exists In-Reply-To: References: <583D383D-6322-4CF3-A8CC-B9E71CC08C0E@gmail.com> Message-ID: <2DC5F21F-32BC-44D9-A884-C445B4DF5DF3@gmail.com> Boris I don?t have other tables with similar names in my table space. Do you create more than one statement using the table as the prefix? Thanks Alessandro On Jul 11, 2014, at 5:15 AM, Boris Kolpackov wrote: > Hi Alessandro, > > Alessandro Bellina writes: > >> One thing I forgot to mention is that if I go to Postgres and attempt >> to deallocate the statement manually I get a notice, that the statement >> name is too long and that it will be truncated. > > Ah, that's definitely something worth mentioning! Now it makes sense. > What most likely happens is that the names get truncated and are no > longer unique. The only way I can think of to resolve this would be > to shorten the table names so that the generated statement names don't > get truncated. Maybe there is also a way to increase the statement name > in Postgres. > > Boris From boris at codesynthesis.com Fri Jul 11 07:01:38 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 11 07:06:42 2014 Subject: [odb-users] Postgres error: 42P05 prepared statement already exists In-Reply-To: <2DC5F21F-32BC-44D9-A884-C445B4DF5DF3@gmail.com> References: <583D383D-6322-4CF3-A8CC-B9E71CC08C0E@gmail.com> <2DC5F21F-32BC-44D9-A884-C445B4DF5DF3@gmail.com> Message-ID: Hi Alessandro, Alessandro Bellina writes: > I don?t have other tables with similar names in my table space. Do > you create more than one statement using the table as the prefix? Yes, there are several statements for each object/table. The way we construct their names is by appending the "statement kind suffix" (e.g., "_persist", "_find", etc) to the table name. If the table name is long and gets truncated, these suffixes are effectively ignored. >From this analysis it is pretty clear that we should make them prefixes and not suffixes. This way we will stand much better chance of ending up with unique names even in case of truncation. I've added this to my TODO list. In the meantime, however, the easiest solution is to shorten the table name (db table pragma). Boris From abellina at gmail.com Fri Jul 11 08:01:13 2014 From: abellina at gmail.com (Alessandro Bellina) Date: Fri Jul 11 08:01:23 2014 Subject: [odb-users] Postgres error: 42P05 prepared statement already exists In-Reply-To: References: <583D383D-6322-4CF3-A8CC-B9E71CC08C0E@gmail.com> <2DC5F21F-32BC-44D9-A884-C445B4DF5DF3@gmail.com> Message-ID: <6C741D0A-428E-4355-8370-E67657ED3577@gmail.com> Ok that makes sense. Thanks for adding it to the TODO as well, seems like it will save you some headaches in the future. Alessandro On Jul 11, 2014, at 6:01 AM, Boris Kolpackov wrote: > Hi Alessandro, > > Alessandro Bellina writes: > >> I don?t have other tables with similar names in my table space. Do >> you create more than one statement using the table as the prefix? > > Yes, there are several statements for each object/table. The way we > construct their names is by appending the "statement kind suffix" > (e.g., "_persist", "_find", etc) to the table name. If the table > name is long and gets truncated, these suffixes are effectively > ignored. > > From this analysis it is pretty clear that we should make them > prefixes and not suffixes. This way we will stand much better > chance of ending up with unique names even in case of truncation. > I've added this to my TODO list. > > In the meantime, however, the easiest solution is to shorten > the table name (db table pragma). > > Boris From boris at codesynthesis.com Mon Jul 14 09:41:54 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Jul 14 09:47:00 2014 Subject: [odb-users] ODB without persistent objects? In-Reply-To: <652564741.2762121404149010724.JavaMail.defaultUser@defaultHost> References: <652564741.2762121404149010724.JavaMail.defaultUser@defaultHost> Message-ID: Hi, Sorry for the late reply. You email was caught up by the spam filter and it took me a while to detect this. frankiegp@libero.it writes: > I would like to know whether I could exploit ODB Query functionalities > without creating any C++ classes to be mapped to the tables of a > database. I mean: > - I have an existent database managed by a hypothetical DBMS (one among > PostgreSQL, MySQL, Oracle, SQLServer and so on); > - I would like to query my database without taking care of the specific > dialect of the DBMS. > In other words, I would like to write my queries in some high-level > languages (pseudo-sql) and then I would like that my query would be > rewritten by ODB in the SQL-dialect of the specific DBMS. Is it possible? You can use ODB Table Views for that (Section 10.2, "Table Views" in the ODB manual). You will get result extraction into C++ types as well as query parameter binding (_val()/_ref). What you won't get is C++ names for column names as you get with objects. So instead of having this: query::name == "Jonh" && query::age == 18 You will have to write: "name = " + query::_val ("John") + "AND age = " + query::_val (18) If you want to get the first variant, what you can do is still map tables to objects but mark them read-only (Section 14.1.4, "readonly"). Then you can use such objects for queries or use them to create object views. Boris From vincent.j.baker at lmco.com Tue Jul 15 15:09:01 2014 From: vincent.j.baker at lmco.com (Baker, Vincent J) Date: Wed Jul 16 02:25:34 2014 Subject: [odb-users] Error modifying change-tracking odb::vector created with copy constructor Message-ID: <403CE5B984C3E845A56185615F2A73B81BC33FFD@HVXDSP43.us.lmco.com> Hello, I'm having a problem using odb::vector. The following illustrates the issue: odb::vector ov1 = odb::vector(); //Create an odb vector ov1._start(); //Start change tracking (in real application code it's started by database operations) ov1.push_back(11); //Put a data value into the vector odb::vector ov2(ov1); //Create a new odb vector using the copy constructor ov2.modify(0) = 12; //This line causes a core dump It appears that the copy constructor copies the data over, and the change-tracking state of ov2 is set to "tracking". However, the "_data" member of ov2 is null. _data is then referenced by the modify operation. I expected the copy constructor to copy over the change state for the data as well as the data itself, but that doesn't seem to happen. I'm using odb 2.3.0 with gcc 4.6.3. Thanks, Vincent Baker From boris at codesynthesis.com Wed Jul 16 05:37:06 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 16 05:42:12 2014 Subject: [odb-users] Error modifying change-tracking odb::vector created with copy constructor In-Reply-To: <403CE5B984C3E845A56185615F2A73B81BC33FFD@HVXDSP43.us.lmco.com> References: <403CE5B984C3E845A56185615F2A73B81BC33FFD@HVXDSP43.us.lmco.com> Message-ID: Hi Vincent, Baker, Vincent J writes: > It appears that the copy constructor copies the data over [...] This was a bad one. Sometimes two characters make all the difference. Thanks for the report. The fix/patch is here: http://scm.codesynthesis.com/?p=odb/libodb.git;a=commit;h=f8317dd174c60f7fdb1a535abe8a4d8d215e528e Boris From jme22 at 126.com Wed Jul 16 22:20:26 2014 From: jme22 at 126.com (=?GBK?B?t+u5zLqj?=) Date: Thu Jul 17 04:07:26 2014 Subject: [odb-users] l report a bug , and l want to kown how to maping boost.date to the mysql database Message-ID: <1962d1a7.27cc.147421ee22e.Coremail.jme22@126.com> Hello, l cant map the boost.date to the mysql database.l have did the next and report a bug: There are two cpp at the file system: /home/feng/ODBEXAMPLE System:Ubuntu desktop 14.04 boost version :1.55 -----------------------------------main.cpp-------------------------------------------- #include #include #include #include #include #include #include #include using namespace std; using namespace odb::core; int main(int argc, char** argv) { cout<<"feng"<db ( new odb::mysql::database("root","123456","ROSE3") //mysql connetion on local at (3306 root 123456 ROSE3) ); Person l("liu",20,1); transaction t (db->begin ()); db->persist (l); t.commit (); return 0; } ------------------------------Person.cpp--------------------------------------------- #include #define BOOST_DATA_TIME_SOURCE //define the datatime macro #include //load the boost.date library #include using namespace std; using namespace boost::gregorian; #pragma db object class Person { public: std::string Name; int Age; int Sex; boost::gregorian::date Br; //date Person(std::string n,int a,int sex) { Name=n; Age=a; Sex=sex; Br=date(1993,3,25); } private: Person(){}; friend class odb::access; #pragma db id auto unsigned long id_; }; --------------------------------------------------------------------------------------------------------------------- the next l compiling it in the shell: odb -d mysql --generate-query --profile boost/date-time Person.cpp odb -d mysql --generate-query --generate-schema --profile boost/date-time Person.cpp the next l load the Person.sql to the mysql database to create a table all thing gose ok there. the next l compiling the two cpps use g++: g++ -c main.cpp g++ -c Person-odb.cxx the next is link: g++ -o main main.o Person-odb.o -lodb-mysql -lodb -lboost_thread -lpthread -L/usr/local/lib -lboost_system but link failed,the output is: ------------------------------Output---------------------- g++: error: main.o: ????????? g++: error: Person-odb.o: ????????? feng@feng:/usr/local/lib$ cd feng@feng:~$ cd /home/feng/ODBEXAMPLE/ feng@feng:~/ODBEXAMPLE$ feng@feng:~/ODBEXAMPLE$ g++ -c main.cpp feng@feng:~/ODBEXAMPLE$ g++ -c Person-odb.cxx feng@feng:~/ODBEXAMPLE$ g++ -o main main.o Person-odb.o -lodb-mysql -lodb -lboost_thread -lpthread -L/usr/local/lib -lboost_system Person-odb.o?????odb::boost::date_time::special_value::special_value()??? Person-odb.cxx:(.text._ZN3odb5boost9date_time13special_valueC2Ev[_ZN3odb5boost9date_time13special_valueC5Ev]+0x1f)???vtable for odb::boost::date_time::special_value??????? Person-odb.o?????odb::mysql::default_value_traits::set_image(st_mysql_time&, bool&, boost::gregorian::date const&)??? Person-odb.cxx:(.text._ZN3odb5mysql20default_value_traitsIN5boost9gregorian4dateELNS0_16database_type_idE11EE9set_imageER13st_mysql_timeRbRKS4_[_ZN3odb5mysql20default_value_traitsIN5boost9gregorian4dateELNS0_16database_type_idE11EE9set_imageER13st_mysql_timeRbRKS4_]+0x63)???typeinfo for odb::boost::date_time::special_value??????? Person-odb.o?????odb::boost::date_time::special_value::~special_value()??? Person-odb.cxx:(.text._ZN3odb5boost9date_time13special_valueD2Ev[_ZN3odb5boost9date_time13special_valueD5Ev]+0x13)???vtable for odb::boost::date_time::special_value??????? collect2: error: ld returned 1 exit status --------------------------------------------------------------------- so , l report the bug. but l want to kown how to maping the boost:::gregorian::date to the mysql database. there are so unclear write in the ODB Manual . l am a Software Engineer from China,and use the odb product in my app, l am very supportive of your product . l am very hope to deal with my trouble. Thanks From boris at codesynthesis.com Thu Jul 17 04:06:01 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Jul 17 04:11:06 2014 Subject: [odb-users] l report a bug , and l want to kown how to maping boost.date to the mysql database In-Reply-To: <1962d1a7.27cc.147421ee22e.Coremail.jme22@126.com> References: <1962d1a7.27cc.147421ee22e.Coremail.jme22@126.com> Message-ID: Hi, ??? writes: > feng@feng:~/ODBEXAMPLE$ g++ -o main main.o Person-odb.o -lodb-mysql -lodb -lboost_thread -lpthread -L/usr/local/lib -lboost_system > Person-odb.o?????odb::boost::date_time::special_value::special_value()??? You need to link to the Boost date_time library. Add -lboost_date_time to the above linking command line. Boris From qgjie at 163.com Tue Jul 22 03:24:50 2014 From: qgjie at 163.com (qgjie) Date: Tue Jul 22 08:19:48 2014 Subject: [odb-users] =?gbk?q?help=A3=A1_I_want_to_query_some_line=2820_ro?= =?gbk?q?ws=29_from_a_table=2C__how_to_do_it_=3F_?= Message-ID: I have define tow object: one is "line" , the other is "FixedLine". class Line { public: Line() {} friend class odb::access; long Line_Id; char Line_Title[PLATFORM_NAME_STRLEN]; string Line_SubTxt; int Line_Price; int Line_VipPrice; ptime create_Time; ptime destroy_Time; shared_ptr admin; shared_ptr pics; shared_ptr towns; }; class FixedLine : public Line { public: FixedLine(int price, int vipprice):Line() {} private: FixedLine() {} friend class odb::access; int type; }; Now, I want to query 20 rows from the object FixedLine How can I implementation? I known the SQL like this "select type from FixedLine limit 0, 20", but ODB ? USE VIEW ? thanks! From cresanta at me.com Tue Jul 22 09:12:07 2014 From: cresanta at me.com (Bruce Cresanta) Date: Tue Jul 22 09:13:16 2014 Subject: [odb-users] Special Schema. Message-ID: <16FCF9FD-BE2A-41ED-9B5F-AC65646B4A93@me.com> Boris, I need a master and detail related in one (master) to many (detail). The master should have auto-id, but the detail will not have a primary key. I need to write 12M objects to the detail at a time. I want it to be indexed with a BTREE on Date and related to a date/time in master. How to achieve this? Bruce From boris at codesynthesis.com Wed Jul 23 02:57:53 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 23 03:02:58 2014 Subject: [odb-users] =?utf-8?B?aGVscO+8gSBJIHdh?= =?utf-8?Q?nt?= to query some line(20 rows) from a table, how to do it ? In-Reply-To: References: Message-ID: Hi, qgjie writes: > I known the SQL like this "select type from FixedLine limit 0, 20", > but ODB? USE VIEW ? You can easily append any SQL clauses to object queries. Here is an earlier post that shows how to add LIMIT/OFFSET: http://www.codesynthesis.com/pipermail/odb-users/2012-January/000429.html Boris From boris at codesynthesis.com Wed Jul 23 03:02:39 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 23 03:07:45 2014 Subject: [odb-users] Special Schema. In-Reply-To: <16FCF9FD-BE2A-41ED-9B5F-AC65646B4A93@me.com> References: <16FCF9FD-BE2A-41ED-9B5F-AC65646B4A93@me.com> Message-ID: Hi Bruce, Bruce Cresanta writes: > I need a master and detail related in one (master) to many (detail). The > master should have auto-id, but the detail will not have a primary key. I > need to write 12M objects to the detail at a time. I want it to be indexed > with a BTREE on Date and related to a date/time in master. How to achieve > this? >From this description I have a very vague idea of what you trying to achieve. Also, you didn't say what you have tried/what doesn't work. It is possible in ODB to have an object without id. Also the index definition pragmas are pretty flexible. So what's the problem? Boris From cresanta at me.com Wed Jul 23 07:04:18 2014 From: cresanta at me.com (Bruce Cresanta) Date: Wed Jul 23 07:11:14 2014 Subject: [odb-users] Special Schema. In-Reply-To: References: <16FCF9FD-BE2A-41ED-9B5F-AC65646B4A93@me.com> Message-ID: Hi Boris, Going through the whole documentation and haven?t uncovered the tools yet to achieve what I want to achieve, that?s why I asked the question. I only want to use 1 auto-id on the master side per iteration of 12M into the detail. I can?t burn up 12M auto-id?s per iteration. I?ll get back in touch when I have a couple classes. Regards, Bruce On Jul 23, 2014, at 12:02 AM, Boris Kolpackov wrote: > Hi Bruce, > > Bruce Cresanta writes: > >> I need a master and detail related in one (master) to many (detail). The >> master should have auto-id, but the detail will not have a primary key. I >> need to write 12M objects to the detail at a time. I want it to be indexed >> with a BTREE on Date and related to a date/time in master. How to achieve >> this? > > From this description I have a very vague idea of what you trying to > achieve. Also, you didn't say what you have tried/what doesn't work. > It is possible in ODB to have an object without id. Also the index > definition pragmas are pretty flexible. So what's the problem? > > Boris From armz4pxq at gmail.com Wed Jul 23 21:12:30 2014 From: armz4pxq at gmail.com (first last) Date: Thu Jul 24 04:13:59 2014 Subject: [odb-users] shared pointers to abstract classes Message-ID: Hi Boris, I have a very basic question. How can I make persistent a class that has as a member a pointer to an abstract class. Something like: class person { ... abstract } class operator : public person { ... real } class programmer : public person { ... real } class employer { shared_ptr employee; // this can be either an operator or a programmer } Thanks, Dan From mne at qosmotec.com Thu Jul 24 04:37:54 2014 From: mne at qosmotec.com (Marcel Nehring) Date: Thu Jul 24 04:39:01 2014 Subject: [odb-users] Is there an API documentation? Message-ID: Hello, I started to work with ODB and was wondering if there is any lightweight API documentation like a doxygen page or similar. The only documentation I could find is the ODB manual, which is quite detailed and exhaustive but it is also quite hard to use when looking for a specific feature or description of a method parameter and stuff like this. A simple API documentation which lists the classes, methods etc. and gives a brief explanation would be very helpful here. For example I am working with Oracle and I could not find a method to specify the schema I want to use nor one to query for the currently used schema. Regards, MNE From boris at codesynthesis.com Thu Jul 24 06:20:31 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Jul 24 06:25:38 2014 Subject: [odb-users] shared pointers to abstract classes In-Reply-To: References: Message-ID: Hi Dan, first last writes: > How can I make persistent a class that has as a member a pointer to an > abstract class. > > class employer { > > shared_ptr employee; // this can be either an operator or a programmer > > } By using polymorphic inheritance (Section 8.2 in the manual). Boris From boris at codesynthesis.com Thu Jul 24 06:27:13 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Jul 24 06:32:17 2014 Subject: [odb-users] Is there an API documentation? In-Reply-To: References: Message-ID: Hi Marcel, Marcel Nehring writes: > I started to work with ODB and was wondering if there is any lightweight > API documentation like a doxygen page or similar. The only documentation > I could find is the ODB manual, which is quite detailed and exhaustive > but it is also quite hard to use when looking for a specific feature or > description of a method parameter and stuff like this. A simple API > documentation which lists the classes, methods etc. and gives a brief > explanation would be very helpful here. No, unfortunately there is no such thing. The best alternative for this is probably to just open the header. Most of the functions/argumets/etc in there should be self-explanatory. > For example I am working with Oracle and I could not find a method > to specify the schema I want to use nor one to query for the currently > used schema. Not sure what you mean by "schema" in the Oracle content. It could mean the "database namespace" (Section 14.1.8) or the "statements that create tables/etc" (Section 3.4 and Chapter 13). Boris From mne at qosmotec.com Thu Jul 24 06:51:45 2014 From: mne at qosmotec.com (Marcel Nehring) Date: Thu Jul 24 06:52:40 2014 Subject: AW: [odb-users] Is there an API documentation? In-Reply-To: References: Message-ID: Hi Boris, that's a pity. I think it would be a great help to have something like this around for a quick reference. Might we have it available somewhere in the future? When talking about the schema I was referring to the "database namespace". In the meantime I checked the manual on this and it looks like ODB supports only a single schema. That is, there is no ODB way of issuing a "alter session set current_schema = xyz". Is this correct? Regards, Marcel From murray.wilson at gmail.com Thu Jul 24 14:20:15 2014 From: murray.wilson at gmail.com (Murray Wilson) Date: Thu Jul 24 14:20:25 2014 Subject: [odb-users] Re: odb-users Digest, Vol 47, Issue 12 In-Reply-To: <201407241600.s6OG0ik2028293@codesynthesis.com> References: <201407241600.s6OG0ik2028293@codesynthesis.com> Message-ID: When talking about the schema I was referring to the "database namespace". In the meantime I checked the manual on this and it looks like ODB supports only a single schema. That is, there is no ODB way of issuing a "alter session set current_schema = xyz". Is this correct? Databse Schema are covered in the ODB manual in section 14.1.8: http://www.codesynthesis.com/products/odb/doc/manual.xhtml#14.1.8 "In ODB, a schema for a table of a persistent class can be specified at the class level, C++ namespace level, or the file level. To assign a schema to a specific persistent class we can use the schema specifier, for example: #pragma db object schema("accounting") class employee { ... }; If we are also assigning a table name, then we can use a shorter notation by specifying both the schema and the table name in the table specifier: #pragma db object table("accounting.employee") class employee { ... }; If we want to assign a schema to all the persistent classes in a C++ namespace, then, instead of specifying the schema for each class, we can specify it once at the C++ namespace level. For example: #pragma db namespace schema("accounting") namespace accounting { #pragma db object class employee { ... }; #pragma db object class employer { ... }; } If we want to assign a schema to all the persistent classes in a file, then we can use the --schema ODB compiler option. For example: odb ... --schema accounting ... An alternative to this approach with the same effect is to assign a schema to the global namespace: #pragma db namespace() schema("accounting")" On Thu, Jul 24, 2014 at 12:00 PM, wrote: > Send odb-users mailing list submissions to > odb-users@codesynthesis.com > > To subscribe or unsubscribe via the World Wide Web, visit > http://codesynthesis.com/mailman/listinfo/odb-users > or, via email, send a message with subject or body 'help' to > odb-users-request@codesynthesis.com > > You can reach the person managing the list at > odb-users-owner@codesynthesis.com > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of odb-users digest..." > > > Today's Topics: > > 1. shared pointers to abstract classes (first last) > 2. Is there an API documentation? (Marcel Nehring) > 3. Re: shared pointers to abstract classes (Boris Kolpackov) > 4. Re: Is there an API documentation? (Boris Kolpackov) > 5. AW: [odb-users] Is there an API documentation? (Marcel Nehring) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 23 Jul 2014 18:12:30 -0700 > From: first last > Subject: [odb-users] shared pointers to abstract classes > To: odb-users@codesynthesis.com > Message-ID: > > Content-Type: text/plain; charset=UTF-8 > > Hi Boris, > > > I have a very basic question. > > How can I make persistent a class that has as a member a pointer to an > abstract class. > > Something like: > > > class person { > > ... abstract > > } > > > class operator : public person { > > ... real > > } > > > class programmer : public person { > > ... real > > } > > > class employer { > > shared_ptr employee; // this can be either an operator or a > programmer > > } > > > Thanks, > > > Dan > > > ------------------------------ > > Message: 2 > Date: Thu, 24 Jul 2014 08:37:54 +0000 > From: Marcel Nehring > Subject: [odb-users] Is there an API documentation? > To: "odb-users@codesynthesis.com" > Message-ID: > Content-Type: text/plain; charset="us-ascii" > > Hello, > > I started to work with ODB and was wondering if there is any lightweight API documentation like a doxygen page or similar. The only documentation I could find is the ODB manual, which is quite detailed and exhaustive but it is also quite hard to use when looking for a specific feature or description of a method parameter and stuff like this. A simple API documentation which lists the classes, methods etc. and gives a brief explanation would be very helpful here. > For example I am working with Oracle and I could not find a method to specify the schema I want to use nor one to query for the currently used schema. > > Regards, > MNE > > > ------------------------------ > > Message: 3 > Date: Thu, 24 Jul 2014 12:20:31 +0200 > From: Boris Kolpackov > Subject: Re: [odb-users] shared pointers to abstract classes > To: first last > Cc: odb-users@codesynthesis.com > Message-ID: > Content-Type: text/plain; charset=us-ascii > > Hi Dan, > > first last writes: > >> How can I make persistent a class that has as a member a pointer to an >> abstract class. >> >> class employer { >> >> shared_ptr employee; // this can be either an operator or a programmer >> >> } > > By using polymorphic inheritance (Section 8.2 in the manual). > > Boris > > > > ------------------------------ > > Message: 4 > Date: Thu, 24 Jul 2014 12:27:13 +0200 > From: Boris Kolpackov > Subject: Re: [odb-users] Is there an API documentation? > To: Marcel Nehring > Cc: "odb-users@codesynthesis.com" > Message-ID: > Content-Type: text/plain; charset=us-ascii > > Hi Marcel, > > Marcel Nehring writes: > >> I started to work with ODB and was wondering if there is any lightweight >> API documentation like a doxygen page or similar. The only documentation >> I could find is the ODB manual, which is quite detailed and exhaustive >> but it is also quite hard to use when looking for a specific feature or >> description of a method parameter and stuff like this. A simple API >> documentation which lists the classes, methods etc. and gives a brief >> explanation would be very helpful here. > > No, unfortunately there is no such thing. The best alternative for this > is probably to just open the header. Most of the functions/argumets/etc > in there should be self-explanatory. > > >> For example I am working with Oracle and I could not find a method >> to specify the schema I want to use nor one to query for the currently >> used schema. > > Not sure what you mean by "schema" in the Oracle content. It could mean > the "database namespace" (Section 14.1.8) or the "statements that create > tables/etc" (Section 3.4 and Chapter 13). > > Boris > > > > ------------------------------ > > Message: 5 > Date: Thu, 24 Jul 2014 10:51:45 +0000 > From: Marcel Nehring > Subject: AW: [odb-users] Is there an API documentation? > To: "odb-users@codesynthesis.com" > Message-ID: > Content-Type: text/plain; charset="us-ascii" > > Hi Boris, > > that's a pity. I think it would be a great help to have something like this around for a quick reference. Might we have it available somewhere in the future? > > When talking about the schema I was referring to the "database namespace". In the meantime I checked the manual on this and it looks like ODB supports only a single schema. That is, there is no ODB way of issuing a "alter session set current_schema = xyz". Is this correct? > > Regards, > Marcel > > > > ------------------------------ > > _______________________________________________ > odb-users mailing list > odb-users@codesynthesis.com > http://codesynthesis.com/mailman/listinfo/odb-users > > > End of odb-users Digest, Vol 47, Issue 12 > ***************************************** From boris at codesynthesis.com Fri Jul 25 02:19:26 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Jul 25 02:24:31 2014 Subject: [odb-users] Is there an API documentation? In-Reply-To: References: Message-ID: Hi Marcel, Marcel Nehring writes: > that's a pity. I think it would be a great help to have something like > this around for a quick reference. Might we have it available somewhere > in the future? I just generated Doxygen docs for libodb and libodb-oracle (with cross- references): http://codesynthesis.com/~boris/tmp/odb/doxygen/libodb/doc/html/ http://codesynthesis.com/~boris/tmp/odb/doxygen/libodb-oracle/doc/html/ There isn't any "text" documentation in there since we don't use Doxygen comments in our source code. So can you give it a try and let me know if it is useful? > When talking about the schema I was referring to the "database namespace". > In the meantime I checked the manual on this and it looks like ODB supports > only a single schema. That is, there is no ODB way of issuing a "alter > session set current_schema = xyz". Is this correct? You can run any Oracle SQL statement with ODB: db.execute ("alter session set current_schema = xyz"); So the idea is not to use any schema prefix when defining the objects so that the current sessions schema is used to create/access their tables. Then you can execute the above statement at any time you need to switch to a different schema. Boris From mne at qosmotec.com Tue Jul 29 10:05:45 2014 From: mne at qosmotec.com (Marcel Nehring) Date: Tue Jul 29 10:07:09 2014 Subject: [odb-users] reuse inheritance with templated base class Message-ID: <015e8e73bec14aa982c48ad15ba4e7b3@QEX.qosmotec.com> Hi, I am trying to run the ODB compiler on my code but I keep getting "no data member designated as an object id" and "optimistic class without a version member" errors. To me it looks like that this happens when the base class is a template class. The following example does not compile, producing the two error messages above. However, if one changes Base to a none template class, it compiles just fine. Do I have to specify something else to make this work? Is this a bug or expected behavior? Regards, Marcel #include #pragma db object optimistic template class Base { public: Base() : m_id(0), m_version(0) {}; virtual ~Base() {}; virtual void foo() = 0; protected: friend class odb::access; private: #pragma db id auto long long m_id; #pragma db version const unsigned long long m_version; }; #pragma db object class Derived : public Base { public: Derived() {}; ~Derived() {}; void foo() {}; protected: friend class odb::access; }; From boris at codesynthesis.com Tue Jul 29 14:15:27 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Jul 29 14:20:34 2014 Subject: [odb-users] reuse inheritance with templated base class In-Reply-To: <015e8e73bec14aa982c48ad15ba4e7b3@QEX.qosmotec.com> References: <015e8e73bec14aa982c48ad15ba4e7b3@QEX.qosmotec.com> Message-ID: Hi Marcel, Marcel Nehring writes: > #pragma db object optimistic > template > class Base ODB does not support persistent class templates. The persistent data (m_id and m_version in your case) rarely depends on the template argument (it doesn't in your case) so what you can do is split your base into two classes: #pragma db object optimistic class BaseData { #pragma db id auto long long m_id; #pragma db version const unsigned long long m_version; }; // Note: not persistent object template class Base { ... }; #pragma db object class Derived : public Base, public BaseData { ... }; Boris From mne at qosmotec.com Wed Jul 30 04:31:01 2014 From: mne at qosmotec.com (Marcel Nehring) Date: Wed Jul 30 04:32:21 2014 Subject: AW: [odb-users] reuse inheritance with templated base class In-Reply-To: References: <015e8e73bec14aa982c48ad15ba4e7b3@QEX.qosmotec.com> Message-ID: <60d0da4d602943c6b28317d64452335c@QEX.qosmotec.com> Hi Boris, uhm, that is quite a limitation. I did not expect that. The example I provided was only a short, self-contained, compilable example to demonstrate the error I am getting. In fact my code *does* contain persistent classes where the persistent data depends on the template argument. Regards, Marcel -----Urspr?ngliche Nachricht----- Von: Boris Kolpackov [mailto:boris@codesynthesis.com] Gesendet: Dienstag, 29. Juli 2014 20:15 An: Marcel Nehring Cc: odb-users@codesynthesis.com Betreff: Re: [odb-users] reuse inheritance with templated base class Hi Marcel, Marcel Nehring writes: > #pragma db object optimistic > template > class Base ODB does not support persistent class templates. The persistent data (m_id and m_version in your case) rarely depends on the template argument (it doesn't in your case) so what you can do is split your base into two classes: #pragma db object optimistic class BaseData { #pragma db id auto long long m_id; #pragma db version const unsigned long long m_version; }; // Note: not persistent object template class Base { ... }; #pragma db object class Derived : public Base, public BaseData { ... }; Boris From boris at codesynthesis.com Wed Jul 30 05:10:15 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Jul 30 05:15:20 2014 Subject: [odb-users] reuse inheritance with templated base class In-Reply-To: <60d0da4d602943c6b28317d64452335c@QEX.qosmotec.com> References: <015e8e73bec14aa982c48ad15ba4e7b3@QEX.qosmotec.com> <60d0da4d602943c6b28317d64452335c@QEX.qosmotec.com> Message-ID: Hi Marcel, Marcel Nehring writes: > uhm, that is quite a limitation. I did not expect that. The example I > provided was only a short, self-contained, compilable example to > demonstrate the error I am getting. In fact my code *does* contain > persistent classes where the persistent data depends on the template > argument. Implementing proper persistent class templates support is a whole different level of complexity. In fact, I am not sure this is even possible (or makes sense) since a persistent class operates on a concrete table that has concrete columns with concrete types. If the column (member) type is a template argument, we cannot generate statements (which are just static strings) nor code that uses them. What we could probably do is support persistent class template instantiations. We already do something similar for composite values (copying an example from the manual): template struct point { T x; T y; T z; }; typedef point int_point; #pragma db value(int_point) #pragma db object class object { ... int_point center_; }; Note that the template itself is not a composite value (in ODB sense). It is the instantiation that is the value. We could do the same for objects: class Derived; typedef Base DerivedBase; #pragma db object(DerivedBase) optimistic #pragma db object class Derived : public DerivedBase { ... }; Not particularly pretty. The way we handle this for composite values right now, you would also have to specify the object id pragma, etc., for each instantiation: #pragma db object(DerivedBase) optimistic #pragma db object(DerivedBase) id(DerivedBase::m_id) #pragma db object(DerivedBase) version(DerivedBase::m_version) But we will probably be able to fix this so that you don't have to (i.e., we will "apply" pragmas that were specified for the template to each instantiation). Would something like this work for you? Boris From mne at qosmotec.com Wed Jul 30 05:57:13 2014 From: mne at qosmotec.com (Marcel Nehring) Date: Wed Jul 30 05:58:32 2014 Subject: AW: [odb-users] reuse inheritance with templated base class In-Reply-To: References: <015e8e73bec14aa982c48ad15ba4e7b3@QEX.qosmotec.com> <60d0da4d602943c6b28317d64452335c@QEX.qosmotec.com> Message-ID: Hi Boris, I understand that proper support of persistent class templates can get complex, but yes I guess what you proposed should work for me. Thanks. Regards, Marcel -----Urspr?ngliche Nachricht----- Von: Boris Kolpackov [mailto:boris@codesynthesis.com] Gesendet: Mittwoch, 30. Juli 2014 11:10 An: Marcel Nehring Cc: odb-users@codesynthesis.com Betreff: Re: [odb-users] reuse inheritance with templated base class Hi Marcel, Marcel Nehring writes: > uhm, that is quite a limitation. I did not expect that. The example I > provided was only a short, self-contained, compilable example to > demonstrate the error I am getting. In fact my code *does* contain > persistent classes where the persistent data depends on the template > argument. Implementing proper persistent class templates support is a whole different level of complexity. In fact, I am not sure this is even possible (or makes sense) since a persistent class operates on a concrete table that has concrete columns with concrete types. If the column (member) type is a template argument, we cannot generate statements (which are just static strings) nor code that uses them. What we could probably do is support persistent class template instantiations. We already do something similar for composite values (copying an example from the manual): template struct point { T x; T y; T z; }; typedef point int_point; #pragma db value(int_point) #pragma db object class object { ... int_point center_; }; Note that the template itself is not a composite value (in ODB sense). It is the instantiation that is the value. We could do the same for objects: class Derived; typedef Base DerivedBase; #pragma db object(DerivedBase) optimistic #pragma db object class Derived : public DerivedBase { ... }; Not particularly pretty. The way we handle this for composite values right now, you would also have to specify the object id pragma, etc., for each instantiation: #pragma db object(DerivedBase) optimistic #pragma db object(DerivedBase) id(DerivedBase::m_id) #pragma db object(DerivedBase) version(DerivedBase::m_version) But we will probably be able to fix this so that you don't have to (i.e., we will "apply" pragmas that were specified for the template to each instantiation). Would something like this work for you? Boris From boris at codesynthesis.com Thu Jul 31 05:48:14 2014 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Jul 31 05:53:19 2014 Subject: [odb-users] reuse inheritance with templated base class In-Reply-To: References: <015e8e73bec14aa982c48ad15ba4e7b3@QEX.qosmotec.com> <60d0da4d602943c6b28317d64452335c@QEX.qosmotec.com> Message-ID: Hi Marcel, Ok, I have the first part of this functionality implemented. I uncovered one interesting issues in that it is now hard to distinguish (at the API level) whether something like P is a smart pointer or a persistent class. So in case of a persistent class template instantiation, one may have to specify the object type explicitly, as in: db.persist (o); Rather than: db.persist (o); This is not a major issue and won't affect your use-case since you don't actually persist instantiations but only use them as (abstract) bases. Still, this is the kind of complications that I am cautious of. As a result, I would like to get some experience using this feature before I go ahead and implement the second part of what we talked about (applying pragmas specified for class templates to their instantiations). In fact, chances are good that this won't even be necessary because of this possible arrangement: #pragma db object abstract struct base_data { #pragma db id auto unsigned long id; #pragma db version unsigned long version; }; template struct base: public base_data { T x; }; typedef base base_derived; #pragma db object(base_derived) abstract #pragma db object struct derived: public base_derived { int n; }; It has the added benefit of minimizing the generated code size since all the base instantiations will reuse the code generated for base_data for data member that do not depend on template arguments. I have the above code working in a test. Will this setup work for your application? If so, would you like me to build you a pre-release binary so that you can give it a try (let me know which platform)? Boris From mne at qosmotec.com Thu Jul 31 06:28:54 2014 From: mne at qosmotec.com (Marcel Nehring) Date: Thu Jul 31 06:30:14 2014 Subject: AW: [odb-users] reuse inheritance with templated base class In-Reply-To: References: <015e8e73bec14aa982c48ad15ba4e7b3@QEX.qosmotec.com> <60d0da4d602943c6b28317d64452335c@QEX.qosmotec.com> Message-ID: <06f186deb62f49e5a19c2669702b6bbb@QEX.qosmotec.com> Hi Boris, Thanks for your effort. So I would have to split all my persistent template classes into two? A template part and a none template part? Actually I would like to avoid that since it would mean a blow up in my number of classes. However, if I understand you correctly this would only be a possible optimization to reduce code size and to avoid the need to respecify pragmas for every instantiation? However, yes, it would be great if you could build a pre-release binary. I'm currently using the prebuild odb-2.3.0-i686-windows. Regards, Marcel