From boris at codesynthesis.com Wed Aug 1 09:36:23 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Aug 1 09:24:29 2012 Subject: [odb-users] How to make a "lazy" QList? In-Reply-To: References: Message-ID: Hi Rene, Rene Jensen writes: > Do you have any plans for making a similar way to postpone loading of > many-to-many keys and arrays? Yes, this is on our TODO list. There also doesn't seem to be any architectural/technical issues in supporting something like this. Container loading is already a separate statement execution so doing that at a later time shouldn't be a problem. Probably the biggest effort will be to implement lazy variants for all the standard, Boost, and Qt containers. Just need to find the time. Boris From rene at catatonic.dk Wed Aug 1 11:57:51 2012 From: rene at catatonic.dk (Rene Jensen) Date: Wed Aug 1 11:57:59 2012 Subject: [odb-users] How to make a "lazy" QList? In-Reply-To: References: Message-ID: > > > Do you have any plans for making a similar way to postpone loading of > > many-to-many keys and arrays? > > Yes, this is on our TODO list. There also doesn't seem to be any > architectural/technical issues in supporting something like this. > Container loading is already a separate statement execution so > doing that at a later time shouldn't be a problem. Probably the > biggest effort will be to implement lazy variants for all the > standard, Boost, and Qt containers. Just need to find the time. > > Hi Boris, Excellent to hear. Now that I have pondered the ramifications of my own suggestion, I think that making real lazy variants of lists, vectors etc. might be overdoing it. What is needed is a (programmer-friendly) technique to control loading of parts of an object. E.g. class Author { ... #pragma db lazyloaded QList > authorsBooks; #pragma db lazyloaded vector > authorsArticles; ... } Author* A = ... some default load procedure ... will not load "lazyloaded" members A->authorsBooks.size() // 0 ... not loaded db->load_lazymembers (A); A->authorsBooks.size() // 34 Regards, Rene From boris at codesynthesis.com Thu Aug 2 08:39:53 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 2 08:27:54 2012 Subject: [odb-users] How to make a "lazy" QList? In-Reply-To: References: Message-ID: Hi Rene, Rene Jensen writes: > Now that I have pondered the ramifications of my own suggestion, I think > that making real lazy variants of lists, vectors etc. might be overdoing > it. What is needed is a (programmer-friendly) technique to control loading > of parts of an object. E.g. > > > class Author > { ... > #pragma db lazyloaded > QList > authorsBooks; > > #pragma db lazyloaded > vector > authorsArticles; > ... > } > > Author* A = ... some default load procedure ... will not load "lazyloaded" > members > A->authorsBooks.size() // 0 ... not loaded > > db->load_lazymembers (A); > > A->authorsBooks.size() // 34 Yes, we've thought about this approach also. The major problem here is that there is no good place to store the loaded/unloaded flag. While it might not be necessary from the users' perspective (i.e., we can say that it is the user's responsibility to know whether the lazy parts are loaded or not), it gets tricky when we consider an operation like update(). ODB has no way of knowing whether the container is loaded (and thus we need to write the elements to the database) or not (and thus we should do nothing for this container). The other issue is that you may have several lazy containers in a class and may want to load only one of them at a time. With the above approach there is no way to specify which member to load. Doing something like db->load_lazymembers (A, &Author::authorsBooks) will work but will require authorsBooks to be public. Plus: A->authorsBooks.load (); Feels more natural than: db->load_lazymembers (A, &Author::authorsBooks); The other alternative that we are considering is to provide a smart pointer-like class template that implements laziness: class Author { ... #pragma db lazyloaded odb::lazy > > authorsBooks; }; A->authorsBooks.load (); A->authorsBooks->size (); (*A->authorsBooks)[0]->load (); // Not very elegant. This is the approach that will probably be most suitable for simple members if/when we decide to support lazy loading for them as well. On a more conceptual level, what seems to be the ultimate goal is to have the ability to segment data members into lazy-loadable sections. Supporting lazy loading for simple members will require a separate statement for each member, if we do it member-by-member. This is a significant overhead. So grouping members into as few sections as possible is a good idea. Maybe something along these lines: class Author { odb::lazy_section publications; #pragma db lazy(publications) QList > authorsBooks; #pragma db lazy(publications) vector > authorsArticles; }; if (!A->publications.loaded ()) A->publications.load (); // Loads authorsBooks and authorsArticles. Just some thoughts. Boris From rene at catatonic.dk Thu Aug 2 14:03:49 2012 From: rene at catatonic.dk (Rene Jensen) Date: Thu Aug 2 14:03:57 2012 Subject: [odb-users] How to make a "lazy" QList? In-Reply-To: References: Message-ID: On a more conceptual level, what seems to be the ultimate goal is > to have the ability to segment data members into lazy-loadable > sections. Supporting lazy loading for simple members will require > a separate statement for each member, if we do it member-by-member. > This is a significant overhead. So grouping members into as few > sections as possible is a good idea. Maybe something along these > lines: > > class Author > { > > odb::lazy_section publications; > > #pragma db lazy(publications) > QList > authorsBooks; > > #pragma db lazy(publications) > vector > authorsArticles; > > }; > > if (!A->publications.loaded ()) > A->publications.load (); // Loads authorsBooks and authorsArticles. > > Just some thoughts. > > Boris > This is an utterly brilliant idea in every conceivable way that I can immediately think of. Cheers From dctomm at gmail.com Thu Aug 2 20:39:36 2012 From: dctomm at gmail.com (Douglas Tomm) Date: Thu Aug 2 20:39:45 2012 Subject: [odb-users] how to represent mysql timestamps? Message-ID: <501B1DC8.9000002@gmail.com> what is the correct type to represent mysql timestamps? the convention given in section 19.4.1 of the manual did not work for me. when i put this in my class: #pragma db type("timestamp") not_null column("created") boost::posix_time::ptime m_created; the following compiler messages appeared. what is the correct way to do this? my environment is: * odb 2.0.0 * gcc 4.1.2 * boost 1.46.1 * centos 5 linux thank you, doug /usr/local/include/odb/mysql/traits.hxx: In static member function 'static void odb::mysql::default_value_traits >::set_image(typename odb::mysql::image_traits::image_type&, bool&, T) [with T = boost::posix_time::ptime, odb::mysql::database_type_id ID = id_timestamp]': build/cpp/odb/MyTest-odb.cxx:294: instantiated from here /usr/local/include/odb/mysql/traits.hxx:320: error: no matching function for call to 'st_mysql_time::st_mysql_time(boost::posix_time::ptime&)' /usr/include/mysql/mysql_time.h:48: note: candidates are: st_mysql_time::st_mysql_time() /usr/include/mysql/mysql_time.h:48: note: st_mysql_time::st_mysql_time(const st_mysql_time&) /usr/local/include/odb/mysql/traits.hxx: In static member function 'static void odb::mysql::default_value_traits >::set_value(T&, const typename odb::mysql::image_traits::image_type&, bool) [with T = boost::posix_time::ptime, odb::mysql::database_type_id ID = id_timestamp]': build/cpp/odb/MyTest-odb.cxx:379: instantiated from here /usr/local/include/odb/mysql/traits.hxx:311: error: no matching function for call to 'boost::posix_time::ptime::ptime(const st_mysql_time&)' /usr/include/boost/date_time/posix_time/ptime.hpp:53: note: candidates are: boost::posix_time::ptime::ptime() /usr/include/boost/date_time/posix_time/ptime.hpp:49: note: boost::posix_time::ptime::ptime(boost::date_time::special_values) /usr/include/boost/date_time/posix_time/ptime.hpp:45: note: boost::posix_time::ptime::ptime(const boost::date_time::counted_time_rep&) /usr/include/boost/date_time/posix_time/ptime.hpp:42: note: boost::posix_time::ptime::ptime(boost::gregorian::date) /usr/include/boost/date_time/posix_time/ptime.hpp:39: note: boost::posix_time::ptime::ptime(boost::gregorian::date, boost::posix_time::time_duration) /usr/include/boost/date_time/posix_time/ptime.hpp:32: note: boost::posix_time::ptime::ptime(const boost::posix_time::ptime&) From boris at codesynthesis.com Fri Aug 3 06:59:10 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Aug 3 06:47:00 2012 Subject: [odb-users] how to represent mysql timestamps? In-Reply-To: <501B1DC8.9000002@gmail.com> References: <501B1DC8.9000002@gmail.com> Message-ID: Hi Doug Douglas Tomm writes: > When i put this in my class: > > #pragma db type("timestamp") not_null column("created") > boost::posix_time::ptime m_created; > > the following compiler messages appeared. My guess is you didn't add the boost/date-time profile to your ODB compiler command line (you will also need to link to the libodb-boost library): odb ... -p boost/date-time ... Remember that the database mapping for Boost types is provides by the Boost profile. See Chapter 19, "Boost Profile" in the ODB Manual for details. Boris From doug at plaxo.com Fri Aug 3 12:48:14 2012 From: doug at plaxo.com (Douglas Tomm) Date: Fri Aug 3 12:48:23 2012 Subject: [odb-users] how to represent mysql timestamps? In-Reply-To: References: <501B1DC8.9000002@gmail.com> Message-ID: <501C00CE.1050305@plaxo.com> yep, that's all i needed to do. thanks again! d On 8/3/12 3:59 AM, Boris Kolpackov wrote: > Hi Doug > > Douglas Tomm writes: > >> When i put this in my class: >> >> #pragma db type("timestamp") not_null column("created") >> boost::posix_time::ptime m_created; >> >> the following compiler messages appeared. > My guess is you didn't add the boost/date-time profile to your ODB > compiler command line (you will also need to link to the libodb-boost > library): > > odb ... -p boost/date-time ... > > Remember that the database mapping for Boost types is provides by > the Boost profile. See Chapter 19, "Boost Profile" in the ODB > Manual for details. > > Boris > From eric.b.sum at lmco.com Mon Aug 6 09:09:29 2012 From: eric.b.sum at lmco.com (Sum, Eric B) Date: Mon Aug 6 09:10:00 2012 Subject: [odb-users] SQLITE unable to open db multiple threads Message-ID: Hi, I am persisting objects into a sqlite database from multiple threads. However, I am getting odd results caught with odb exceptions. I get sqlite error 14: unable to open database multiple times throughout the execution of my program, and only a fraction of the objects persisted are present in the database. I assume I am getting this error because one of the threads is unable to establish a connection to the database. I am aware that you are unable to do concurrent writes to the sqlite database due to its exclusive locking mechanism, but I thought that there would be some scheduling/blocking scheme used inherently by odb to schedule the order of the persists from the different threads. How do I fix this? Any ideas on why I am getting this error? Thanks, Eric From eric.b.sum at lmco.com Mon Aug 6 09:25:26 2012 From: eric.b.sum at lmco.com (Sum, Eric B) Date: Mon Aug 6 09:25:40 2012 Subject: [odb-users] RE: SQLITE unable to open db multiple threads Message-ID: Sorry, one more follow-up question. The odb manual states that by default, a sqlite connection_pool_factory is used, which behind the scenes uses the shared_cache/unlock_notify mechanism. From reading about the shared_cache/unlock_notify mechanism it seems that "The sqlite3_unlock_notify() interface is designed for use in systems that have a separate thread assigned to each database connection" and the shared_cache mechanism allows the same cache to be shared across the entire process that contains all of its threads. How do I create a database connection for each individual separate thread as it seems the intended use is? 1. I tried explicitly calling connection_ptr c(db.connection()) in each thread on the existing db object created in the main function that was passed to each thread. 2. I tried passing the existing db object to each thread, which I suppose does not create a new connection and uses the existing one across multiple threads. 3. I tried called the sqlite db constructor in each thread to open the existing database created in the main function in READWRITE mode, which I assume creates a connection in each thread to use. None of these seemed to work. Any help or insight on this is much appreciated. Thanks again, Eric From: Sum, Eric B Sent: Monday, August 06, 2012 9:09 AM To: 'odb-users@codesynthesis.com' Subject: SQLITE unable to open db multiple threads Hi, I am persisting objects into a sqlite database from multiple threads. However, I am getting odd results caught with odb exceptions. I get sqlite error 14: unable to open database multiple times throughout the execution of my program, and only a fraction of the objects persisted are present in the database. I assume I am getting this error because one of the threads is unable to establish a connection to the database. I am aware that you are unable to do concurrent writes to the sqlite database due to its exclusive locking mechanism, but I thought that there would be some scheduling/blocking scheme used inherently by odb to schedule the order of the persists from the different threads. How do I fix this? Any ideas on why I am getting this error? Thanks, Eric From boris at codesynthesis.com Mon Aug 6 11:00:55 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Aug 6 10:48:14 2012 Subject: [odb-users] Re: Binary Representation of PostgreSQL arrays In-Reply-To: <5E840D29AD76D2429C1B0FD628D3F360D37C@lcldn-mail12.Liquid-Capital.liquidcap.com> References: <5E840D29AD76D2429C1B0FD628D3F360D37C@lcldn-mail12.Liquid-Capital.liquidcap.com> Message-ID: Hi Leo, [CC'ing odb-users to my reply.] Leonardo Greca writes: > I have been playing with the new experimental version of ODB and things > are behaving pretty well. > > Using the example you posted on the blog below, I was able to store stl > containers using the pgsql types: DOUBLE PRECISION[][], TEXT[][] and > INTEGER[][] > http://www.codesynthesis.com/~boris/blog/2012/07/18/custom-database-to-cxx-type-mapping-in-odb/ Glad to hear it is working well. > All that is done by converting the array to its text representation; e.g., > "{n1,n2,...}". > > The problem is that parsing strings is very expensive for both CPU and > network. It seems that the PostgreSQL developers don't think this overhead is significant since their canonical array literal format is {n1,n2,...}. While there is also a binary (over-the-wire) format for arrays (and other types), it is not explicitly documented (except in the source code) and is quite complex. I found this page that has a pretty easy to follow description for a one-dimensional array of 4-byte integers: http://stackoverflow.com/questions/4016412/postgresqls-libpq-encoding-for-binary-transport-of-array-data Based on that information, the binary representation of a 3-integer array (e.g., {1, 2, 3}) takes 44 bytes. In comparison, the "{1,2,3}" string literal takes only 9 bytes. One major overhead of the binary array format in PG is that each element is accompanied by a 4-byte size. > I understand it is possible to save any container as bytea but that would > make the db unreadable. > > I was wondering if it is possible to use ODB to send a binary/compact > representation of HSTORE or DOUBLE PRECISION[][] to postgres and still > have it stored as HSTORE or DOUBLE PRECISION[][]. The short answer is, yes, it is possible but is not easy. Below is the long answer: First of all, simple cast to/from BYTEA doesn't work. I did some more digging and found two PG functions that seem relevant: array_send and array_recv. These functions are used to write and read the binary, over-the-wire representation of arrays. First I tried array_send which takes an array as an argument and returns BYTEA. I added it to the 'from' conversion expression and indeed I got the binary representation of an array. I tried it on INTEGER[] and could see exactly the output described on that page I mentioned above. Unfortunately, conversion in the other direction is not that easy. We cannot use array_recv directly because it expects an internal buffer representation rather than BYTEA. However, this can be worked around with a simple server-side C function. Below is its source code. For more information on adding C function extensions, refer to the PG documentation. #include "postgres.h" #include "lib/stringinfo.h" #include "utils/array.h" #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif PG_FUNCTION_INFO_V1(sql_array_recv); Datum sql_array_recv (PG_FUNCTION_ARGS) { bytea *d = PG_GETARG_BYTEA_PP(0); StringInfoData si; si.data = VARDATA (d); si.len = si.maxlen = VARSIZE(d) - VARHDRSZ; si.cursor = 0; fcinfo->arg[0] = (Datum)&si; PG_RETURN_ARRAYTYPE_P(array_recv (fcinfo)); } Once this function is compiled into a shared library, say array_recv.so, we can load it into the PG database like this (using GNU/Linux as an example): su postgres psql -d dbname CREATE FUNCTION int_array_recv(bytea, integer, integer) RETURNS integer[] AS '$libdir/array_recv.so', 'sql_array_recv' LANGUAGE C STRICT; GRANT EXECUTE ON FUNCTION int_array_recv(bytea, integer, integer) TO PUBLIC; Once this is done, we can use int_array_recv in the 'to' conversion expression. The second argument to this function is the Oid of the array element (e.g., 23 for INTEGER). And the third argument should be 0. So for INTEGER[] we can have a mapping pragma like this: #pragma db map type("INTEGER *\\[(\\d*)\\]") \ as("BYTEA") \ to("int_array_recv((?), 23, 0)") \ from("array_send ((?))") After that the only thing left is to write the code (in the value_traits specialization) that can read and write the PG binary array format. Boris From boris at codesynthesis.com Mon Aug 6 13:15:40 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Aug 6 13:02:57 2012 Subject: [odb-users] SQLITE unable to open db multiple threads In-Reply-To: References: Message-ID: Hi Eric, Sum, Eric B writes: > I am persisting objects into a sqlite database from multiple threads. > However, I am getting odd results caught with odb exceptions. I get > sqlite error 14: unable to open database multiple times throughout > the execution of my program, and only a fraction of the objects > persisted are present in the database. Can you take a look at the common/threads test in the odb-tests package and see if there is anything different between that code and your application. You can either try to model your code after the test, or you can try to change the test to model your application and thus reproduce the problem. If you can reproduce it with the test, then I would be happy to take a look. > I am aware that you are unable to do concurrent writes to the sqlite > database due to its exclusive locking mechanism, but I thought that > there would be some scheduling/blocking scheme used inherently by odb > to schedule the order of the persists from the different threads. That's correct. And the common/threads test is the proof that it works without doing anything special/extra. Besides other things, this test persists multiple objects from multiple threads into the same database, simultaneously. > The odb manual states that by default, a sqlite connection_pool_factory > is used, which behind the scenes uses the shared_cache/unlock_notify > mechanism. From reading about the shared_cache/unlock_notify mechanism > it seems that "The sqlite3_unlock_notify() interface is designed for > use in systems that have a separate thread assigned to each database > connection" and the shared_cache mechanism allows the same cache to > be shared across the entire process that contains all of its threads. > How do I create a database connection for each individual separate > thread as it seems the intended use is? This is all done automatically by ODB/connection_pool_factory. > 1. I tried explicitly calling connection_ptr c(db.connection()) in each > thread on the existing db object created in the main function that was > passed to each thread. No, you don't need to do that. > 2. I tried passing the existing db object to each thread, which I suppose > does not create a new connection and uses the existing one across > multiple threads. That's exactly how it should be done: you pass a single sqlite::database instance to all your threads and this instance will "issue" an individual connection (via the pool_factory) to each thread. Again, see the 'threads' test for an example. > 3. I tried called the sqlite db constructor in each thread to open the > existing database created in the main function in READWRITE mode, > which I assume creates a connection in each thread to use. Nop, you shouldn't do that. Just create a single sqlite::database in main() and pass it to all your threads. Boris From christian.fontana at gmail.com Tue Aug 7 18:31:21 2012 From: christian.fontana at gmail.com (Christian Fontana) Date: Tue Aug 7 18:31:29 2012 Subject: [odb-users] Ubuntu compiling issue Message-ID: Hello, I'm trying to compile odb 2.0.1 on my ubuntu machine. The g++ version is: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) The gcc versione is: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) The error is: checking whether g++ supports plugins... no configure: error: g++ does not support plugins; reconfigure GCC with --enable-plugin But as you can see above the --enable-plugin was used by ubuntu team to package the compiler. What can I do? thanks in advance Christian F. From boris at codesynthesis.com Wed Aug 8 02:16:34 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Aug 8 02:03:31 2012 Subject: [odb-users] Ubuntu compiling issue In-Reply-To: References: Message-ID: Hi Christian, Christian Fontana writes: > The error is: > checking whether g++ supports plugins... no > configure: error: g++ does not support plugins; reconfigure GCC with > --enable-plugin > > But as you can see above the --enable-plugin was used by ubuntu team to > package the compiler. I think you need to install the gcc-4.6-plugin-dev package. Quoting the INSTALL file: " Note also that for pre-packaged GCC, plugin headers are usually distributed in a separate package, normally called gcc-plugin-dev or similar. You will need to install this package in order to build ODB. For Debian/Ubuntu, this package is called gcc-X.Y-plugin-dev, for example: apt-get install gcc-4.7-plugin-dev For RedHat/Fedora, this package is called gcc-plugin-devel, for example: yum install gcc-plugin-devel " Boris From christian.fontana at gmail.com Wed Aug 8 03:36:21 2012 From: christian.fontana at gmail.com (Christian Fontana) Date: Wed Aug 8 03:36:28 2012 Subject: [odb-users] Ubuntu compiling issue In-Reply-To: References: Message-ID: Thanks, Probably I read the INSTALL file to fast. It SOLVED the problem. Regards Christian On Wed, Aug 8, 2012 at 8:16 AM, Boris Kolpackov wrote: > Hi Christian, > > Christian Fontana writes: > > > The error is: > > checking whether g++ supports plugins... no > > configure: error: g++ does not support plugins; reconfigure GCC with > > --enable-plugin > > > > But as you can see above the --enable-plugin was used by ubuntu team to > > package the compiler. > > I think you need to install the gcc-4.6-plugin-dev package. Quoting > the INSTALL file: > > " > Note also that for pre-packaged GCC, plugin headers are usually > distributed in a separate package, normally called gcc-plugin-dev > or similar. You will need to install this package in order to build > ODB. For Debian/Ubuntu, this package is called gcc-X.Y-plugin-dev, > for example: > > apt-get install gcc-4.7-plugin-dev > > For RedHat/Fedora, this package is called gcc-plugin-devel, for > example: > > yum install gcc-plugin-devel > " > > Boris > From yb947835908 at gmail.com Fri Aug 10 22:14:18 2012 From: yb947835908 at gmail.com (=?GB2312?B?1KzUrLHz?=) Date: Fri Aug 10 22:14:26 2012 Subject: [odb-users] how to install ODB on windows Message-ID: I'm a new learner. What exactly do I have to do to install the ODB on windows? It would be very helpful to tell me more details about it. Many thanks!! From boris at codesynthesis.com Sun Aug 12 05:54:35 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Aug 12 05:40:49 2012 Subject: [odb-users] how to install ODB on windows In-Reply-To: References: Message-ID: Hi, yb947835908@gmail.com writes: > I'm a new learner. What exactly do I have to do to install the ODB on > windows? It would be very helpful to tell me more details about it. There is the "Installing ODB on Windows" page which gives a high- level overview of the steps: http://www.codesynthesis.com/products/odb/doc/install-windows.xhtml Also make sure that for every package that you choose to install you read the INSTALL file that comes inside the package. Boris From oded at geek.co.il Sun Aug 12 05:52:48 2012 From: oded at geek.co.il (Oded Arbel) Date: Sun Aug 12 05:52:55 2012 Subject: [odb-users] ODB roadmap to 2.1? Message-ID: To ODB maintainers. I'm considering using ODB to replace a custom database abstraction layer in a high-risk project with a rather longish release cycle. I'm wondering if I should use ODB 2.0 or should I wait for 2.1 (I'm interested in custom type mapping and better Oracle support, but its not a must for me), which mostly depends if I I can develop with the 2.1 alphas now and have the 2.1 release in time for my release date - so my question is, can you guys provide some info about the timeline for the 2.1 release? I've looked on the web site and didn't see a roadmap document for ODB (I may have missed it?) Thanks in advance, -- Oded From duhai_lee at qq.com Sun Aug 12 21:22:40 2012 From: duhai_lee at qq.com (=?ISO-8859-1?B?SnVzdGxpdmU=?=) Date: Mon Aug 13 02:00:39 2012 Subject: [odb-users] directly generate .h and .cxx by connected db? Message-ID: could odb command only generate cxx files from .h file? Can I connect to the database directly generated . H files and .cxx files? From boris at codesynthesis.com Mon Aug 13 02:22:38 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Aug 13 02:08:44 2012 Subject: [odb-users] ODB roadmap to 2.1? In-Reply-To: References: Message-ID: Hi Oded, Oded Arbel writes: > so my question is, can you guys provide some info about the timeline > for the 2.1 release? The plan is to release 2.1.0 around mid-September. Boris From boris at codesynthesis.com Mon Aug 13 02:24:21 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Aug 13 02:10:28 2012 Subject: [odb-users] directly generate .h and .cxx by connected db? In-Reply-To: References: Message-ID: Hi, Justlive writes: > Can I connect to the database directly generated . H files and .cxx > files? No, not yet. Though this feature is on our TODO list so at some point we plan to provide this functionality. Boris From yb947835908 at gmail.com Mon Aug 13 13:54:10 2012 From: yb947835908 at gmail.com (=?GB2312?B?1KzUrLHz?=) Date: Mon Aug 13 13:54:17 2012 Subject: [odb-users] compiling error Message-ID: Thank u so much,it helped a lot!! Since I've install ODB successfully, I start to learn to use it by compiling and running the examples. And I encounter with this problem: While compiling the mapping example,it says: (traits.hxx':error:unable to open in read mode ). What dose that mean and how can I solve this? On the other hand, I tried to remove the (--hxx-prologue '#include "traits.hxx"' ) option while compiling and manually added text (#include "traits.hxx") into the generated file person-odb.hxx , it worked just well. PS: My compiling and running environment: Windows 7 , Microsoft Visual Studio 2008 , sqlite3. By the way, there is a tiny error: in the file \odb-examples-2.0.0\c++11\README, you miss a '-' in the command line,that is,it should be "odb ... --std c++11..." , not "odb ... -std c++11...". From Davide.Anastasia at qualitycapital.com Tue Aug 14 04:49:18 2012 From: Davide.Anastasia at qualitycapital.com (Davide Anastasia) Date: Tue Aug 14 04:50:11 2012 Subject: [odb-users] Unit Testing and ODB Message-ID: Hi All, I am wondering whether there is any way to programmatically control the content of a database in order to write "well define" unit testing. In particular, I wrote a function that retrieves an object if available, or adds it to the database and I want to be sure that the database doesn't contain that object before running my tests (using some kind of fixture). Best, Davide Davide Anastasia Analyst, Research & Development Quality Capital Management Ltd. QCM House * Horizon Business Village No. 1 Brooklands Road Weybridge * Surrey KT13 0TJ United Kingdom Tel: +44 (0) 1932 334 400 Fax: +44 (0) 1932 334 415 Email: Davide.Anastasia@QualityCapital.com www.qualitycapital.com ________________________________ This email and any attachments are confidential and intended solely for the use of the individual(s) to whom it is addressed. Any views or opinions presented are solely those of the author and do not necessarily represent those of Quality Capital Management Ltd. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, printing, forwarding or copying of this email is strictly prohibited. Please contact the sender if you have received this email in error. You should also be aware that emails are susceptible to interference and you should not assume that the contents of this email originated from the sender above or that they have been accurately reproduced in their original form. Quality Capital Management Ltd is authorised and regulated by the Financial Services Authority in the UK and is a member of the National Futures Association in the US. ________________________________ From interceptor at 126.com Mon Aug 13 21:58:10 2012 From: interceptor at 126.com (=?GBK?B?0e63sg==?=) Date: Tue Aug 14 08:38:04 2012 Subject: [odb-users] help!how to generate database Message-ID: <43e64fc7.1aa0a.13922da3b26.Coremail.interceptor@126.com> Hi,Every one,I'm trying to use odb right now,and I have red manual,and did some test.but I just find that odb don't support index column(not ordered container?s index column of a data member,just index to speed search),it means i should manual add it? Thans for your reply! panda From boris at codesynthesis.com Tue Aug 14 09:00:58 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Aug 14 08:46:51 2012 Subject: [odb-users] compiling error In-Reply-To: References: Message-ID: Hi, yb947835908@gmail.com writes: > And I encounter with this problem: While compiling the mapping example, > it says: (traits.hxx':error:unable to open in read mode). > What dose that mean and how can I solve this? > On the other hand, I tried to remove the (--hxx-prologue '#include > "traits.hxx"' ) option while compiling and manually added text (#include > "traits.hxx") into the generated file person-odb.hxx , it worked just well. The command line in the README was not valid for Windows (I've fixed that). Try this variant instead, which works for both POSIX and Windows shells: --hxx-prologue "#include \"traits.hxx\"" > By the way, there is a tiny error: in the file > \odb-examples-2.0.0\c++11\README, you miss a '-' in the command > line, that is, it should be "odb ... --std c++11..." , not "odb ... -std > c++11...". Fixed. Thanks for reposting this! Boris From boris at codesynthesis.com Tue Aug 14 09:03:55 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Aug 14 08:49:51 2012 Subject: [odb-users] help!how to generate database In-Reply-To: <43e64fc7.1aa0a.13922da3b26.Coremail.interceptor@126.com> References: <43e64fc7.1aa0a.13922da3b26.Coremail.interceptor@126.com> Message-ID: Hi, interceptor@126.com writes: > But I just find that odb don't support index column. This feature has been added for the upcoming 2.1.0 release. Also there is a pre-release available, if you don't want to wait: http://www.codesynthesis.com/pipermail/odb-announcements/2012/000017.html Boris From boris at codesynthesis.com Tue Aug 14 09:15:40 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Aug 14 09:01:36 2012 Subject: [odb-users] Unit Testing and ODB In-Reply-To: References: Message-ID: Hi Davide, Davide Anastasia writes: > I am wondering whether there is any way to programmatically control the > content of a database in order to write "well define" unit testing. > > In particular, I wrote a function that retrieves an object if available, > or adds it to the database and I want to be sure that the database > doesn't contain that object before running my tests (using some kind of > fixture). I am not clear what kind of functionality you are looking for here. You can make sure that the database is empty by re-creating the schema (i.e., dropping all the tables and re-creating them). After that, if your tests expect some content in the database, then you will need to add it using the standard ODB mechanisms. This is how ODB's own test suite does it. Now, if you want to do this many times during your test execution, then embedded (into C++) schema creation code will probably be more convenient than a standalone SQL file. You can also partition your schema into segments if you don't want to re-create the while database for every test (which could be slow). For more information on this functionality refer to Section 3.3, "Database" in the ODB manual. Boris From eric.b.sum at lmco.com Wed Aug 15 11:09:34 2012 From: eric.b.sum at lmco.com (Sum, Eric B) Date: Wed Aug 15 11:12:35 2012 Subject: [odb-users] SQL Statement Tracer Message-ID: Hi, I have been trying out the SQL Statement execution tracer. It's a very neat and useful tool for debugging. I have a question about it (I am using a sqlite database). When I use the tracer to print out the statements (either with the built-in stderr_tracer or my own odb::sqlite::tracer implementation), I have been unable to print out the values associated with the SQL statement. For example, if I persist objects into a table. It prints something along the lines of INSERT INTO table VALUES (?,?,?) It looks like the parameters for the sqlite_statement are being print out unbound. I was wondering if it is possible to get it to print something like: INSERT INTO table VALUES(1,2,3) where the bound values appear rather than "?" I have looked through the odb::sqlite::statement class to see if there are any particular functions specific to sqlite that I can use for this, but I am unable to find any. I might have missed it. Thanks so much, Eric From yb947835908 at gmail.com Wed Aug 15 11:59:11 2012 From: yb947835908 at gmail.com (=?GB2312?B?1KzUrLHz?=) Date: Wed Aug 15 11:59:19 2012 Subject: [odb-users] error:Unknown pragma; Message-ID: Hi! I've run all the examples successfully.After that,I start to build my own project using odb. Those files(.hxx,.c.xx,.ixx) are generated successfully,but after that,when compiling the project on VS2008, it says"error :Unknown pragma" in those lines that contain "#pragma db ....", also it can't recognise the "db" from text " auto_ptr db (new odb::mysql::database (argc, argv));". By the way, when adding the .ixx into the project, I ignored to create new .rules file, since I don't know what that means. So,my problem is, after the files are generated, how to build a new project , how to compile , and at last create the .exe file. Thanks! Environment : vs2008, windows 7, sqlites. From boris at codesynthesis.com Thu Aug 16 08:33:40 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 16 08:19:15 2012 Subject: [odb-users] SQL Statement Tracer In-Reply-To: References: Message-ID: Hi Eric, Sum, Eric B writes: > It prints something along the lines of > > INSERT INTO table VALUES (?,?,?) > > It looks like the parameters for the sqlite_statement are being print > out unbound. I was wondering if it is possible to get it to print > something like: > > INSERT INTO table VALUES(1,2,3) where the bound values appear rather > than "?" No, this is not possible. ODB uses prepared statements and passes all the parameters in binary form (i.e., ODB actually never constructs a string like "INSERT INTO table VALUES(1,2,3)"). Adding this functionality would involve quite a bit of effort/code bloat. It is also a fairly "hairy" problem if you start to think about it. For example, how do we print BLOBs. What if the data is very long (say multiple megabytes)? What about national characters? If you want to see actual values, then I suggest that you look for this support in your database logs. In case of SQLite, there is the sqlite3_trace() function. However, I don't think it will print values for parameters in prepared statements either. Boris From boris at codesynthesis.com Thu Aug 16 08:48:50 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 16 08:34:22 2012 Subject: [odb-users] error:Unknown pragma; In-Reply-To: References: Message-ID: Hi, yb947835908@gmail.com writes: > I start to build my own project using odb. > > Those files (.hxx,.c.xx,.ixx) are generated successfully, but after that, > when compiling the project on VS2008, it says > > "error :Unknown pragma" in those lines that contain "#pragma db ...." Normally this is a warning. I think you instructed your VC++ compiler to treat all warnings as errors. For more information on how to suppress these warnings/errors, see Section 12.6, "C++ Compiler Warnings" in the ODB manual. > also it can't recognise the "db" from text " auto_ptr db (new > odb::mysql::database (argc, argv));". I assume you are using the database.hxx file from one of the examples. If so, then you need to define one of the DATABASE_* macros to select the database that you would like to use (e.g., DATABASE_SQLITE). Alternatively, you can remove database.hxx and create the database directly. For example: #include int main (int argc, char* argv[]) { odb::sqlite::database db (argc, argv); ... } Boris From yb947835908 at gmail.com Fri Aug 17 22:43:01 2012 From: yb947835908 at gmail.com (=?GB2312?B?1KzUrLHz?=) Date: Fri Aug 17 22:43:08 2012 Subject: [odb-users] Can I define views wherever I want ? Message-ID: Hi! Must I define all the views in the .hxx file(the input file of the ODB compiler) ? What if I don't know what views I may use at first? Can I define views wherever I want to ,for example, in my main function? Thanks! From yo at miguelrevilla.com Sat Aug 18 06:23:04 2012 From: yo at miguelrevilla.com (=?UTF-8?Q?Miguel_Revilla_Rodr=C3=ADguez?=) Date: Sat Aug 18 06:23:13 2012 Subject: [odb-users] std::set> fails Message-ID: Hi, I'm trying to declare an object with a std::set> member, and while the odb compiler works nicely on it and doesn't complain, later the generated code (object-odb.cpp) fails to compile with G++ 4.7.1 with options -O2 -std=c++11. If I change std::set with std::vector, then everything is fine, but I'd prefer to use a set rather than a vector in this case. Any thoughts? Thanks, Miguel From yo at miguelrevilla.com Sat Aug 18 20:06:16 2012 From: yo at miguelrevilla.com (=?UTF-8?Q?Miguel_Revilla_Rodr=C3=ADguez?=) Date: Sat Aug 18 20:06:24 2012 Subject: [odb-users] Trouble with lazy_ptr Message-ID: I'm completely lost on this. Examples compile fine, so it's not an environment problem. Basically I use this files (sorry if it is a bit long, but I'm really, really lost): node.h: #ifndef NODE_H #define NODE_H #include #include #include #include #include "activity.h" #include "userProfile.h" #include "avatar.h" class group ; #pragma db object polymorphic class node { public: node( const std::string &hash, unsigned long creationTime) : hash_(hash), creationTime_(creationTime) {} virtual ~node() = 0 ; void nodeavatar(const odb::lazy_shared_ptr &n) ; const odb::lazy_shared_ptr nodeavatar() ; const std::string nodeHash() ; protected: friend class odb::access ; node() {} #pragma db id auto unsigned long id_ ; std::string hash_ ; unsigned long creationTime_ ; #pragma db value_not_null odb::lazy_shared_ptr nodeavatar_ ; #pragma db value_not_null std::vector > activities_ ; #pragma db value_not_null inverse(nodes_) std::vector > groups_ ; } ; #pragma db object class user : public node { typedef std::vector> friends_type ; public: user( const std::string &hash, unsigned long creationTime, const std::string &username, const std::string &password, const std::string &email, const std::string &creationIP) : node(hash,creationTime), username_(username), password_(password), email_(email), creationIP_(creationIP) {} const unsigned long id() ; const bool verified() ; const bool locked() ; const std::string username() ; const std::string email() ; void verified(const bool &v) ; void locked(const bool &l) ; void email(const std::string &e) ; const std::shared_ptr profile() ; void profile(const std::shared_ptr &p) ; friends_type& friends() ; const friends_type& friends() const ; void addFriend(const std::shared_ptr &u) ; private: friend class odb::access ; user() {} std::string username_ ; std::string password_ ; std::string email_ ; #pragma db default(false) bool verified_ ; #pragma db default(false) bool locked_ ; std::string creationIP_ ; #pragma db not_null std::shared_ptr userProfile_ ; #pragma db value_not_null friends_type friends_ ; } ; #endif // NODE_H ---------------------------------------------------------------- node.cpp: #include "node.h" node::~node() {} void node::nodeavatar(const odb::lazy_shared_ptr &n) { nodeavatar_ = n ; } const odb::lazy_shared_ptr node::nodeavatar() { return nodeavatar_ ; } const std::string node::nodeHash() { return hash_ ; } const unsigned long user::id() { return id_ ; } const bool user::verified() { return verified_ ; } const bool user::locked() { return locked_ ; } const std::string user::username() { return username_ ; } const std::string user::email() { return email_ ; } void user::email(const std::string &e) { email_ = e ; } void user::verified(const bool &v) { verified_ = v ; } void user::locked(const bool &l) { locked_ = l ; } const std::shared_ptr user::profile() { return userProfile_ ; } void user::profile(const std::shared_ptr &p) { userProfile_ = p ; } typedef std::vector> friends_type ; friends_type& user::friends() { return friends_ ; } const friends_type& user::friends() const { return friends_ ; } void user::addFriend(const std::shared_ptr &u) { // friends_.insert(u) ; } ------------------------------------ apiUserFriends.cpp: #include #include #include #include #include #include #include #include "apiUserFriends.h" #include "odbClasses/node.h" #include "odbClasses/node-odb.h" #include "odbClasses/session.h" #include "odbClasses/session-odb.h" apiUserFriends::apiUserFriends(serviceTools *serviceT, WObject *parent) : WResource(parent), serviceT_(serviceT) { } apiUserFriends::~apiUserFriends() { beingDeleted() ; } void apiUserFriends::handleRequest(const Http::Request& request, Http::Response& response) { response.setMimeType("application/json") ; if( serviceT_->checkClientAuth(Utils::urlDecode(*request.getParameter("token")),permissions::permFrontend) && serviceT_->checkSessionAuth(Utils::urlDecode(*request.getParameter("sessionid")),Utils::hexEncode(Utils::md5(request.clientAddress())))) { typedef odb::query query ; typedef odb::result result ; odb::database *db_ = serviceT_->database() ; { typedef std::vector> friends_type ; odb::transaction t (db_->begin()) ; result g(db_->query ( query::token == Utils::urlDecode(*request.getParameter("sessionid")))) ; if(g.size()==1) { for(session& s: g) { std::shared_ptr u(s.sessionUser()) ; std::stringstream friendsStr ; friends_type& f (u->friends()) ; friends_type::iterator it ; for(auto it (f.begin()); it != f.end() ; it++) { odb::lazy_weak_ptr& tmpPtr (*it) ; tmpPtr.load() ; } response.out() << "{\"result\":\"true\",\"friends\":[" ; response.out() << friendsStr.str().substr(0,friendsStr.str().size()-1) ; response.out() << "]}\n" ; } } else { response.out() << "{\"result\":\"error\",\"data\":{\"errormsg\":\"bad_session\"}}\n" ; } t.commit() ; } } else { response.out() << "{\"result\":\"false\"}\n" ; } } When I try to compile I get: [ 2%] Building CXX object CMakeFiles/yajpws.dir/apiUserFriends.cpp.o In file included from /usr/include/odb/lazy-ptr.hxx:643:0, from /home/mine/bettercodes/yajp-backend/odbClasses/node.h:7, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:9: /usr/include/odb/lazy-ptr.ixx: In instantiation of 'std::shared_ptr<_Tp> odb::lazy_weak_ptr::load() const [with T = user]': /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:48:19: required from here /usr/include/odb/lazy-ptr.ixx:1511:5: error: no match for 'operator=' in 'r = ((const odb::lazy_weak_ptr*)this)->odb::lazy_weak_ptr::i_.odb::lazy_ptr_impl::load(0)' /usr/include/odb/lazy-ptr.ixx:1511:5: note: candidates are: In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/memory:87:0, from /usr/include/odb/pointer-traits.hxx:11, from /usr/include/odb/traits.hxx:11, from /usr/include/odb/database.hxx:13, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:1: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:269:19: note: std::shared_ptr<_Tp>& std::shared_ptr<_Tp>::operator=(const std::shared_ptr<_Tp>&) [with _Tp = user; std::shared_ptr<_Tp> = std::shared_ptr] /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:269:19: note: no known conversion for argument 1 from 'odb::object_traits::pointer_type {aka user*}' to 'const std::shared_ptr&' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:273:2: note: template std::shared_ptr& std::shared_ptr::operator=(const std::shared_ptr<_Tp1>&) [with _Tp1 = _Tp1; _Tp = user] /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:273:2: note: template argument deduction/substitution failed: In file included from /usr/include/odb/lazy-ptr.hxx:643:0, from /home/mine/bettercodes/yajp-backend/odbClasses/node.h:7, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:9: /usr/include/odb/lazy-ptr.ixx:1511:5: note: mismatched types 'const std::shared_ptr<_Tp>' and 'odb::object_traits::pointer_type {aka user*}' In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/memory:87:0, from /usr/include/odb/pointer-traits.hxx:11, from /usr/include/odb/traits.hxx:11, from /usr/include/odb/database.hxx:13, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:1: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:282:2: note: template std::shared_ptr& std::shared_ptr::operator=(std::auto_ptr<_Tp1>&&) [with _Tp1 = _Tp1; _Tp = user] /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:282:2: note: template argument deduction/substitution failed: In file included from /usr/include/odb/lazy-ptr.hxx:643:0, from /home/mine/bettercodes/yajp-backend/odbClasses/node.h:7, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:9: /usr/include/odb/lazy-ptr.ixx:1511:5: note: mismatched types 'std::auto_ptr' and 'odb::object_traits::pointer_type {aka user*}' In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/memory:87:0, from /usr/include/odb/pointer-traits.hxx:11, from /usr/include/odb/traits.hxx:11, from /usr/include/odb/database.hxx:13, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:1: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:290:7: note: std::shared_ptr<_Tp>& std::shared_ptr<_Tp>::operator=(std::shared_ptr<_Tp>&&) [with _Tp = user; std::shared_ptr<_Tp> = std::shared_ptr] /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:290:7: note: no known conversion for argument 1 from 'odb::object_traits::pointer_type {aka user*}' to 'std::shared_ptr&&' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:298:2: note: template std::shared_ptr& std::shared_ptr::operator=(std::shared_ptr<_Tp1>&&) [with _Tp1 = _Tp1; _Tp = user] /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:298:2: note: template argument deduction/substitution failed: In file included from /usr/include/odb/lazy-ptr.hxx:643:0, from /home/mine/bettercodes/yajp-backend/odbClasses/node.h:7, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:9: /usr/include/odb/lazy-ptr.ixx:1511:5: note: mismatched types 'std::shared_ptr<_Tp>' and 'odb::object_traits::pointer_type {aka user*}' In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/memory:87:0, from /usr/include/odb/pointer-traits.hxx:11, from /usr/include/odb/traits.hxx:11, from /usr/include/odb/database.hxx:13, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:1: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:306:2: note: template std::shared_ptr& std::shared_ptr::operator=(std::unique_ptr<_Up, _Ep>&&) [with _Tp1 = _Tp1; _Del = _Del; _Tp = user] /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/shared_ptr.h:306:2: note: template argument deduction/substitution failed: In file included from /usr/include/odb/lazy-ptr.hxx:643:0, from /home/mine/bettercodes/yajp-backend/odbClasses/node.h:7, from /home/mine/bettercodes/yajp-backend/apiUserFriends.cpp:9: /usr/include/odb/lazy-ptr.ixx:1511:5: note: mismatched types 'std::unique_ptr<_Tp, _Dp>' and 'odb::object_traits::pointer_type {aka user*}' make[2]: *** [CMakeFiles/yajpws.dir/apiUserFriends.cpp.o] Error 1 make[1]: *** [CMakeFiles/yajpws.dir/all] Error 2 make: *** [all] Error 2 odb files are compiled with: /usr/bin/odb --std c++11 --database pgsql --hxx-suffix .h --ixx-suffix .i --cxx-suffix .cpp --output-dir ${CMAKE_CURRENT_SOURCE_DIR}/odbClasses --generate-query --generate-schema --schema-format sql and C++: g++ -O2 -std=c++11 (4.7.1) I really don't understand those errors. As a clue, if I comment out the line tmpPtr.load(), everything compiles fine; and, if instead of load() I use object_id(), the lazy_ptr returns the correct object ID, so the lazy_ptr looks well formed and well instantiated. Another things is that if I use std::weak_ptr (or shared_ptr for the matter) everything works as expected, except that in some cases it gets on a recursive loop that causes a crash (that's why I need to use lazy pointers). Thanks in advance if you help me out of this :) :) :) Miguel From boris at codesynthesis.com Sun Aug 19 10:08:57 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Aug 19 09:54:02 2012 Subject: [odb-users] Can I define views wherever I want ? In-Reply-To: References: Message-ID: Hi, yb947835908@gmail.com writes: > Must I define all the views in the .hxx file(the input file of the ODB > compiler) ? What if I don't know what views I may use at first? Can I > define views wherever I want to, for example, in my main function? No, this is not supported. While I agree, it would neat to be able to define function-local views (e.g., in main(), as you suggested), this would pose a chicken-and-egg problem. Consider that in order to use the view, you will need to include the header file that contains the database support code for this view (i.e., the -odb.hxx header). So if you define the view in a file, say main.cxx, where you also use it then this file will need to include the main-odb.hxx file that is produced by the ODB compiler. But when you invoke the ODB compiler on main.cxx, no main-odb.hxx is yet available. So you will get a compile error. There are also other problems, such as the need for main-odb.hxx to include the definition of the view (including main.cxx is probably a bad idea). Boris From boris at codesynthesis.com Sun Aug 19 10:26:37 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Aug 19 10:11:41 2012 Subject: [odb-users] std::set> fails In-Reply-To: References: Message-ID: Hi Miguel, Miguel Revilla Rodr?guez writes: > I'm trying to declare an object with a > std::set> member, and while the odb compiler > works nicely on it and doesn't complain, later the generated code > (object-odb.cpp) fails to compile with G++ 4.7.1 with options -O2 > -std=c++11. When reporting that something fails to compile, it is always a good idea to include the diagnostics from the compiler. Without it we can only guess what could have gone wrong. > If I change std::set with std::vector, then everything is fine, but > I'd prefer to use a set rather than a vector in this case. My guess is that the compiler complains there is no operator< defined for odb::lazy_shared_ptr. The reason for this is that it is tricky to come up with a universally-acceptable semantics. For example: 1. How do we compare a transient object to a persistent one? Do we use the underlying pointers and if so what about unloaded pointers? Do we use object ids? 2. When comparing unloaded persistent objects, do we take into account the database? However, if you have some application-specific knowledge that allows you to provide a sensible less-than comparison, then you can easily add it as a second template argument to std::set. For example, if you know that all the objects in your set will be non-NULL and will have valid object ids (i.e., no object with yet unassigned auto id will ever be added to the set), and they will also be from the same database, then you can define an id- based comparison: template struct object_id_comparator { bool operator (const odb::lazy_shared_ptr& x, const odb::lazy_shared_ptr& y) const { return x.object_id () < y.object_id (); } }; Then, in your persistent class, you can have: std::set, object_id_comparator> foo_; Boris From yo at miguelrevilla.com Sun Aug 19 10:31:12 2012 From: yo at miguelrevilla.com (=?UTF-8?Q?Miguel_Revilla_Rodr=C3=ADguez?=) Date: Sun Aug 19 10:31:21 2012 Subject: [odb-users] std::set> fails In-Reply-To: References: Message-ID: Hi, I see. Will try it right now. Sorry for not including the compilator messages. Will inform here if this works. Miguel 2012/8/19 Boris Kolpackov : > Hi Miguel, > > Miguel Revilla Rodr?guez writes: > >> I'm trying to declare an object with a >> std::set> member, and while the odb compiler >> works nicely on it and doesn't complain, later the generated code >> (object-odb.cpp) fails to compile with G++ 4.7.1 with options -O2 >> -std=c++11. > > When reporting that something fails to compile, it is always a good > idea to include the diagnostics from the compiler. Without it we can > only guess what could have gone wrong. > > >> If I change std::set with std::vector, then everything is fine, but >> I'd prefer to use a set rather than a vector in this case. > > My guess is that the compiler complains there is no operator< defined > for odb::lazy_shared_ptr. The reason for this is that it is tricky to > come up with a universally-acceptable semantics. For example: > > 1. How do we compare a transient object to a persistent one? Do > we use the underlying pointers and if so what about unloaded > pointers? Do we use object ids? > > 2. When comparing unloaded persistent objects, do we take into > account the database? > > However, if you have some application-specific knowledge that > allows you to provide a sensible less-than comparison, then you > can easily add it as a second template argument to std::set. > > For example, if you know that all the objects in your set will > be non-NULL and will have valid object ids (i.e., no object with > yet unassigned auto id will ever be added to the set), and they > will also be from the same database, then you can define an id- > based comparison: > > template > struct object_id_comparator > { > bool operator (const odb::lazy_shared_ptr& x, > const odb::lazy_shared_ptr& y) const > { > return x.object_id () < y.object_id (); > } > }; > > Then, in your persistent class, you can have: > > std::set, object_id_comparator> foo_; > > Boris From boris at codesynthesis.com Sun Aug 19 10:58:16 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Aug 19 10:43:19 2012 Subject: [odb-users] Trouble with lazy_ptr In-Reply-To: References: Message-ID: Hi Miguel, > /usr/include/odb/lazy-ptr.ixx:1511:5: error: no match for 'operator=' > in 'r = ((const odb::lazy_weak_ptr*)this)->odb::lazy_weak_ptr::i_.odb::lazy_ptr_impl::load(0)' I believe this error is due to the incompatible canonical object pointer used for your 'node' and 'user' classes (see Section 3.2, "Object and View Pointers" for more information). Specifically, your 'node' class uses the raw pointer (node*) as the object pointer. This is incompatible with all the C++11 shared/weak pointers that you are using in object relationships. So what you need to do is use std::shared_ptr as your object pointer: #pragma db object polymorphic pointer(std::shared_ptr) class node { ... }; Alternatively, you may want to make all your objects use std::shared_ptr as object pointer by default (this way, if you add another class, you won't need to worry about forgetting to add the pointer pragma). This can be done with the --default-pointer ODB compiler option, for example: --default-pointer std::shared_ptr Boris From yo at miguelrevilla.com Sun Aug 19 10:50:59 2012 From: yo at miguelrevilla.com (=?UTF-8?Q?Miguel_Revilla_Rodr=C3=ADguez?=) Date: Sun Aug 19 10:51:07 2012 Subject: [odb-users] Trouble with lazy_ptr In-Reply-To: References: Message-ID: Thank you, Boris. You're the best. It's amazing the amount of C++ that one can learn just by looking at your code and your messages. Thanks again, will put a huge THANKS in my site when it opens. Miguel 2012/8/19 Boris Kolpackov : > Hi Miguel, > >> /usr/include/odb/lazy-ptr.ixx:1511:5: error: no match for 'operator=' >> in 'r = ((const odb::lazy_weak_ptr*)this)->odb::lazy_weak_ptr::i_.odb::lazy_ptr_impl::load(0)' > > I believe this error is due to the incompatible canonical object > pointer used for your 'node' and 'user' classes (see Section 3.2, > "Object and View Pointers" for more information). Specifically, > your 'node' class uses the raw pointer (node*) as the object pointer. > This is incompatible with all the C++11 shared/weak pointers that > you are using in object relationships. So what you need to do is > use std::shared_ptr as your object pointer: > > #pragma db object polymorphic pointer(std::shared_ptr) > class node { > ... > }; > > Alternatively, you may want to make all your objects use std::shared_ptr > as object pointer by default (this way, if you add another class, you > won't need to worry about forgetting to add the pointer pragma). This > can be done with the --default-pointer ODB compiler option, for example: > > --default-pointer std::shared_ptr > > Boris From yo at miguelrevilla.com Sun Aug 19 11:53:34 2012 From: yo at miguelrevilla.com (=?UTF-8?Q?Miguel_Revilla_Rodr=C3=ADguez?=) Date: Sun Aug 19 11:53:43 2012 Subject: [odb-users] std::set> fails In-Reply-To: References: Message-ID: Everything works perfectly now (including the subject in the other mail). Thanks for you patience with such a noob :) Miguel 2012/8/19 Miguel Revilla Rodr?guez : > Hi, > > I see. Will try it right now. Sorry for not including the compilator > messages. Will inform here if this works. > > Miguel > > 2012/8/19 Boris Kolpackov : >> Hi Miguel, >> >> Miguel Revilla Rodr?guez writes: >> >>> I'm trying to declare an object with a >>> std::set> member, and while the odb compiler >>> works nicely on it and doesn't complain, later the generated code >>> (object-odb.cpp) fails to compile with G++ 4.7.1 with options -O2 >>> -std=c++11. >> >> When reporting that something fails to compile, it is always a good >> idea to include the diagnostics from the compiler. Without it we can >> only guess what could have gone wrong. >> >> >>> If I change std::set with std::vector, then everything is fine, but >>> I'd prefer to use a set rather than a vector in this case. >> >> My guess is that the compiler complains there is no operator< defined >> for odb::lazy_shared_ptr. The reason for this is that it is tricky to >> come up with a universally-acceptable semantics. For example: >> >> 1. How do we compare a transient object to a persistent one? Do >> we use the underlying pointers and if so what about unloaded >> pointers? Do we use object ids? >> >> 2. When comparing unloaded persistent objects, do we take into >> account the database? >> >> However, if you have some application-specific knowledge that >> allows you to provide a sensible less-than comparison, then you >> can easily add it as a second template argument to std::set. >> >> For example, if you know that all the objects in your set will >> be non-NULL and will have valid object ids (i.e., no object with >> yet unassigned auto id will ever be added to the set), and they >> will also be from the same database, then you can define an id- >> based comparison: >> >> template >> struct object_id_comparator >> { >> bool operator (const odb::lazy_shared_ptr& x, >> const odb::lazy_shared_ptr& y) const >> { >> return x.object_id () < y.object_id (); >> } >> }; >> >> Then, in your persistent class, you can have: >> >> std::set, object_id_comparator> foo_; >> >> Boris From yb947835908 at gmail.com Wed Aug 22 11:20:08 2012 From: yb947835908 at gmail.com (=?GB2312?B?1KzUrLHz?=) Date: Wed Aug 22 11:20:16 2012 Subject: [odb-users] supporting Chinese? Message-ID: Hi! Does ODB support Chinese word , as the names of the table or column? If it does, how can I get such supporting? If it doesn't , what do U suggest to solve this problem if I absolutely have to use Chinese words as those names? THX!!! From oded at geek.co.il Tue Aug 21 08:55:57 2012 From: oded at geek.co.il (Oded Arbel) Date: Thu Aug 23 04:52:13 2012 Subject: [odb-users] Support more then one database vendor in a single application? Message-ID: Hi ODB people. I'm writing an application that I want to use with multiple database servers, from multiple vendors (actually only two - I use MS-SQL as a "serious database" and SQLite for "database server is optional" mode). I was thinking of writing database agnostic model (with some #ifdefs in the more hairy parts, though for most cases ODB vendor agnostic pragmas are enough), then run the ODB compiler twice to generate two code sets - one for each database vendor, then build two DLLs out of the whole shebang and load either one in the application depending on the runtime configuration. When I started to work on that, I got into a lot of trouble (I'm a C++ newbie, so it may as well be all my fault). Has anyone tried to do something like this, and if so - what approach did you take? The main problem I have is that, building for MS-Windows, I have to use __declspec(dllexport) on the model API, and that causes the VC++ compiler to get really upset that ODB types do not declare dllexports as well. -- Oded From boris at codesynthesis.com Thu Aug 23 06:20:35 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 23 06:04:57 2012 Subject: [odb-users] Support more then one database vendor in a single application? In-Reply-To: References: Message-ID: Hi Oded, Oded Arbel writes: > I'm writing an application that I want to use with multiple database > servers, from multiple vendors (actually only two - I use MS-SQL as a > "serious database" and SQLite for "database server is optional" mode). This is not yet properly supported by ODB, though it is high up on our TODO list. > I was thinking of writing database agnostic model (with some #ifdefs in the > more hairy parts, though for most cases ODB vendor agnostic pragmas are > enough), then run the ODB compiler twice to generate two code sets - one > for each database vendor, then build two DLLs out of the whole shebang and > load either one in the application depending on the runtime configuration. That will probably work if you don't use queries. The problem with queries is that they are a very, very thin layer over the native SQL queries (and this is done for good reasons, specifically to minimize code bloat and maintain good performance). The result of this design is that the actual query code that you use in your application is very-database specific (i.e., a lot of database-specific non-virtual/inline functions). This is actually the biggest obstacle that we need to overcome in order to provide proper multi-database support. The challenge here is on the one hand to maintain good performance for applications that use only one database (probably the majority of them) and on the other to "abstract" the API sufficiently to allow for multi-database support. So if you need queries, the most straightforward approach would probably be to just build two versions of your application (you can also have a "starter program" that decided which version to run). You could also probably go the DLL route, though in this case you will need to package your whole database-using code (and not just the ODB-generated code) into the DLLs. > The main problem I have is that, building for MS-Windows, I have to use > __declspec(dllexport) on the model API, and that causes the VC++ compiler > to get really upset that ODB types do not declare dllexports as well. That's something that we can fix. However, as I mentioned above, it probably won't help you much. Boris From boris at codesynthesis.com Thu Aug 23 06:23:12 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 23 06:07:33 2012 Subject: [odb-users] supporting Chinese? In-Reply-To: References: Message-ID: Hi, yb947835908@gmail.com writes: > Does ODB support Chinese word , as the names of the table or column? This really depends on the database you are using. Specifically, whether the native C API supports Unicode in query text and if so, in what form. So, which database are you using? Boris From boris at codesynthesis.com Mon Aug 27 08:01:30 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Aug 27 07:45:10 2012 Subject: [odb-users] supporting Chinese? In-Reply-To: References: Message-ID: Hi, In the future please keep your replies CC'ed to the odb-users mailing list as discussed in the posting guidelines: http://www.codesynthesis.com/support/posting-guidelines.xhtml yb947835908@gmail.com writes: > Hi,Boris! I'm using Sqlite.As you may know, it's not difficult to write > some codes to make some conversions so that we could use Chinese words on > the Sqlite database. But I don't think those codes works on ODB because of > the generating-code thing. Actaully, I'm totally lost,I don't even know > where to start with, to write the conversion-codes. So, have you got any > ideas? The SQLite C API allows one to execute Unicode statements as long as they are encoded in UTF-8. This means that you can use Unicode table and column names as long as you specify them in UTF-8. I modified the 'hello' example to use letter '?' (e with acute, UTF-8 2-byte encoding is 0xC3, 0x88) in both table and column names: #pragma db object table("p\xC3\x88rson") class person { ... #pragma db column("ag\xC3\x88") unsigned short age_; }; Everything seems to work fine. So if you want to use Chinese in your table/column names with SQLite, then you will need to get their UTF-8 encodings and specify those in the table/column pragmas. Boris From duhai_lee at qq.com Mon Aug 27 21:35:25 2012 From: duhai_lee at qq.com (=?gb18030?B?SnVzdGxpdmU=?=) Date: Tue Aug 28 01:59:26 2012 Subject: [odb-users] =?gb18030?q?support_Multi-field_primary_key=A3=BF?= Message-ID: Hi, there are multiple field primary key table, how can I do? THX From oded at geek.co.il Tue Aug 28 02:47:31 2012 From: oded at geek.co.il (Oded Arbel) Date: Tue Aug 28 03:21:45 2012 Subject: [odb-users] Support more then one database vendor in a single application? In-Reply-To: References: Message-ID: On Thu, Aug 23, 2012 at 1:20 PM, Boris Kolpackov wrote: > > Oded Arbel writes: > > > I was thinking of writing database agnostic model (with some #ifdefs in > > the > > more hairy parts, though for most cases ODB vendor agnostic pragmas are > > enough), then run the ODB compiler twice to generate two code sets - one > > for each database vendor, then build two DLLs out of the whole shebang > > and > > load either one in the application depending on the runtime > > configuration. > > That will probably work if you don't use queries. The problem with > queries is that they are a very, very thin layer over the native > SQL queries (and this is done for good reasons, specifically to > minimize code bloat and maintain good performance). The way I'm doing this is to have the model implementation hide all the queries and expose a business logic API to the rest of the system (as it is done in MVC). While I expect most queries to be quite generic (I don't really see how "SELECT * FROM table" is much different from vendor to vendor), if there is some queries that happen to be vendor specific I can #ifdef it appropriately. The model implementation will be packaged with the ODB vendor-specific generated code into the vendor-specific DLL. > That's something that we can fix. I've noticed that ODB code has a lot of LIBODB_EXPORT symbols all over the place - is thins something I can use to allow VC++ to compile ODB code into a DLL? -- Oded From duhai_lee at qq.com Tue Aug 28 03:04:22 2012 From: duhai_lee at qq.com (=?gb18030?B?SnVzdGxpdmU=?=) Date: Tue Aug 28 08:01:46 2012 Subject: [odb-users] =?gb18030?q?How_to_use_wstring_instead_of_string?= =?gb18030?b?o78=?= Message-ID: Hi there, in my .h file, I define a class member of type is std::wstring. then generate code, it show errors: error: unable to map C++ type '::std::wstring' used in data member 'Report_Id' to a database type how can I do ? thx very much. From boris at codesynthesis.com Tue Aug 28 08:22:45 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Aug 28 08:07:51 2012 Subject: [odb-users] Support more then one database vendor in a single application? In-Reply-To: References: Message-ID: Hi Oded, Oded Arbel writes: > The way I'm doing this is to have the model implementation hide all > the queries and expose a business logic API to the rest of the system > (as it is done in MVC). [...] The model implementation will be packaged > with the ODB vendor-specific generated code into the vendor-specific > DLL. Yes, that will work. In other words, your "model implementation" will wrap the ODB functionality which will not be exposed from the DLL. > I've noticed that ODB code has a lot of LIBODB_EXPORT symbols all over > the place - is thins something I can use to allow VC++ to compile ODB > code into a DLL? No, these are used from the libodb runtime DLL. Note that if you use the above approach, you don't need to export any ODB-generated code from the DLL. The only thing that you should export is the business logic API. Boris From boris at codesynthesis.com Tue Aug 28 08:30:07 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Aug 28 08:13:38 2012 Subject: [odb-users] support Multi-field primary key? In-Reply-To: References: Message-ID: Hi, Justlive writes: > there are multiple field primary key table, how can I do? You can use a composite value type as an object id: #pragma db value struct name { std::string first; std::string last; }; #pragma db object class person { ... #pragma db id name name_; }; For more information, refer to Section 7.2.1, "Composite Object Ids" in the ODB manual. Boris From boris at codesynthesis.com Tue Aug 28 08:38:44 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Aug 28 08:22:15 2012 Subject: [odb-users] How to use =?utf-8?Q?wstri?= =?utf-8?Q?ng_instead_of_string=EF=BC=9F?= In-Reply-To: References: Message-ID: Hi, Justlive writes: > in my .h file, I define a class member of type is std::wstring. > then generate code, it show errors: > error: unable to map C++ type '::std::wstring' used in data member 'Report_Id' to a database type Which database are you using? Note that it is often impossible to say why things don't work without at least some information about your setup. At the minimum you should include the target database, ODB compiler version, operating system name and version, and C++ compiler name and version that you are using. For more on this, see the "Posting Guidelines" page: http://www.codesynthesis.com/support/posting-guidelines.xhtml Boris From oded at geek.co.il Wed Aug 29 11:17:59 2012 From: oded at geek.co.il (Oded Arbel) Date: Wed Aug 29 11:18:08 2012 Subject: [odb-users] Support more then one database vendor in a single application? In-Reply-To: References: Message-ID: Hi Boris. On Tue, Aug 28, 2012 at 3:22 PM, Boris Kolpackov wrote: > > Oded Arbel writes: >> The way I'm doing this is to have the model implementation hide all >> the queries and expose a business logic API to the rest of the system [...] > > Yes, that will work. In other words, your "model implementation" will > wrap the ODB functionality which will not be exposed from the DLL. It will not expose any ODB functionality through the business logic API, but... > Note that if you use the above approach, you don't need to export any > ODB-generated code from the DLL. The only thing that you should export > is the business logic API. I still want to expose the model classes themselves, so that the application can say things like: vector employees = Employee::getAll(); for (vector::iterator it = employees.begin(); it != employees.end(); ++it) it->employer->processSalary(*it); Where Employee and Employer are the model classes used in ODB, and getAll() and processSalary() are business logic methods on these classes. I don't want to have the application compile against ODB headers because that causes VC++ to freak out. It should work fine - unless I use ODB datatypes like odb::nullable, which I need to represent my model correctly, and at which point application code start seeing libodb headers and I get export warnings. -- Oded From oded at geek.co.il Wed Aug 29 14:13:57 2012 From: oded at geek.co.il (Oded Arbel) Date: Wed Aug 29 14:14:06 2012 Subject: [odb-users] Self persisting objects? Message-ID: Hi guys. I'm trying to write a model class that is self contained - i.e. it includes all business logic to manipulate the ODB API and does not require the application to know ODB to operate it. As part of that, I thought it will be cool (and OOish) to be able to create and persist objects using a simple API like this: Employee *e = new Employee("John","Doe"); e->persist(); The implementation of Employee::persist() could be pretty trivial (assuming someone knows how to initialize a database connection. I'm going to leave that as an exercise to the user and assume an already inited static field): void Employee::persist() { odb::transaction t(s_db->begin()); s_db->persist(this); t.commit(); } Unfortunately Visual Studio 10 doesn't like me much and breaks when trying to compile. I've seen database.hxx has a definition for persist(T* o), but the "this" pointer is "const Class*" which won't fit. This is what the compiler has to say (actual class names have been modified to protect the cryptic): ---8<--- 1>------ Build started: Project: data-model, Configuration: Debug Win32 ------ 1> employee.cpp 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(103): error C2504: 'odb::access::object_traits' : base class undefined 1> with 1> [ 1> T=model::Employee 1> ] 1> c:\XXX\data-model\src\employee.cpp(17) : see reference to class template instantiation 'odb::object_traits' being compiled 1> with 1> [ 1> T=model::Employee 1> ] 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(104): error C2146: syntax error : missing ',' before identifier 'pointer_type' 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(104): error C2065: 'pointer_type' : undeclared identifier 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(105): error C2955: 'odb::access::object_factory' : use of class template requires template argument list 1> c:\XXX\libodb-2.0.1\odb\traits.hxx(17) : see declaration of 'odb::access::object_factory' 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2146: syntax error : missing ';' before identifier 'const_pointer_type' 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C3254: 'odb::object_traits' : class contains explicit override 'const_pointer_type' but does not derive from an interface that contains the function declaration 1> with 1> [ 1> T=model::Employee 1> ] 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2838: 'const_pointer_type' : illegal qualified name in member declaration 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2602: 'odb::object_traits::const_pointer_type' is not a member of a base class of 'odb::object_traits' 1> with 1> [ 1> T=model::Employee 1> ] 1> c:\XXX\libodb-2.0.1\odb\traits.hxx(119) : see declaration of 'odb::object_traits::const_pointer_type' 1> with 1> [ 1> T=model::Employee 1> ] 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2868: 'odb::object_traits::const_pointer_type' : illegal syntax for using-declaration; expected qualified-name 1> with 1> [ 1> T=model::Employee 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ---8<--- Any idea what I'm doing wrong here? -- Oded From oded at geek.co.il Wed Aug 29 14:39:39 2012 From: oded at geek.co.il (Oded Arbel) Date: Wed Aug 29 14:39:47 2012 Subject: [odb-users] Re: Self persisting objects? In-Reply-To: References: Message-ID: Actually, NM - sorry to bother. My mistake that I didn't include the generated employee-odb.hxx. After that fix it works fine. On Wed, Aug 29, 2012 at 9:13 PM, Oded Arbel wrote: > Hi guys. > > I'm trying to write a model class that is self contained - i.e. it > includes all business logic to manipulate the ODB API and does not > require the application to know ODB to operate it. > > As part of that, I thought it will be cool (and OOish) to be able to > create and persist objects using a simple API like this: > Employee *e = new Employee("John","Doe"); > e->persist(); > > The implementation of Employee::persist() could be pretty trivial > (assuming someone knows how to initialize a database connection. I'm > going to leave that as an exercise to the user and assume an already > inited static field): > void Employee::persist() { > odb::transaction t(s_db->begin()); > s_db->persist(this); > t.commit(); > } > > Unfortunately Visual Studio 10 doesn't like me much and breaks when > trying to compile. > > I've seen database.hxx has a definition for persist(T* o), but the > "this" pointer is "const Class*" which won't fit. > > This is what the compiler has to say (actual class names have been > modified to protect the cryptic): > ---8<--- > 1>------ Build started: Project: data-model, Configuration: Debug Win32 ------ > 1> employee.cpp > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(103): error C2504: > 'odb::access::object_traits' : base class undefined > 1> with > 1> [ > 1> T=model::Employee > 1> ] > 1> c:\XXX\data-model\src\employee.cpp(17) : see reference to > class template instantiation 'odb::object_traits' being compiled > 1> with > 1> [ > 1> T=model::Employee > 1> ] > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(104): error C2146: syntax error : > missing ',' before identifier 'pointer_type' > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(104): error C2065: 'pointer_type' > : undeclared identifier > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(105): error C2955: > 'odb::access::object_factory' : use of class template requires > template argument list > 1> c:\XXX\libodb-2.0.1\odb\traits.hxx(17) : see declaration > of 'odb::access::object_factory' > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2146: syntax error : > missing ';' before identifier 'const_pointer_type' > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C3254: > 'odb::object_traits' : class contains explicit override > 'const_pointer_type' but does not derive from an interface that > contains the function declaration > 1> with > 1> [ > 1> T=model::Employee > 1> ] > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2838: > 'const_pointer_type' : illegal qualified name in member declaration > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C4430: missing type > specifier - int assumed. Note: C++ does not support default-int > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2602: > 'odb::object_traits::const_pointer_type' is not a member of a base > class of 'odb::object_traits' > 1> with > 1> [ > 1> T=model::Employee > 1> ] > 1> c:\XXX\libodb-2.0.1\odb\traits.hxx(119) : see declaration > of 'odb::object_traits::const_pointer_type' > 1> with > 1> [ > 1> T=model::Employee > 1> ] > 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2868: > 'odb::object_traits::const_pointer_type' : illegal syntax for > using-declaration; expected qualified-name > 1> with > 1> [ > 1> T=model::Employee > 1> ] > ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== > ---8<--- > > Any idea what I'm doing wrong here? > > -- > Oded -- Oded From oded at geek.co.il Thu Aug 30 05:31:53 2012 From: oded at geek.co.il (Oded Arbel) Date: Thu Aug 30 05:32:01 2012 Subject: [odb-users] Re: Self persisting objects? In-Reply-To: References: Message-ID: Re-correction - apparently it didn't work (I'm not sure why I though it does), as I get this error during compilation: libodb-2.0.1\odb\database.ixx(49): error C2440: 'initializing' : cannot convert from 'model::Employee *' to 'const object_pointer &' On Wed, Aug 29, 2012 at 9:39 PM, Oded Arbel wrote: > Actually, NM - sorry to bother. My mistake that I didn't include the > generated employee-odb.hxx. After that fix it works fine. > > On Wed, Aug 29, 2012 at 9:13 PM, Oded Arbel wrote: >> Hi guys. >> >> I'm trying to write a model class that is self contained - i.e. it >> includes all business logic to manipulate the ODB API and does not >> require the application to know ODB to operate it. >> >> As part of that, I thought it will be cool (and OOish) to be able to >> create and persist objects using a simple API like this: >> Employee *e = new Employee("John","Doe"); >> e->persist(); >> >> The implementation of Employee::persist() could be pretty trivial >> (assuming someone knows how to initialize a database connection. I'm >> going to leave that as an exercise to the user and assume an already >> inited static field): >> void Employee::persist() { >> odb::transaction t(s_db->begin()); >> s_db->persist(this); >> t.commit(); >> } >> >> Unfortunately Visual Studio 10 doesn't like me much and breaks when >> trying to compile. >> >> I've seen database.hxx has a definition for persist(T* o), but the >> "this" pointer is "const Class*" which won't fit. >> >> This is what the compiler has to say (actual class names have been >> modified to protect the cryptic): >> ---8<--- >> 1>------ Build started: Project: data-model, Configuration: Debug Win32 ------ >> 1> employee.cpp >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(103): error C2504: >> 'odb::access::object_traits' : base class undefined >> 1> with >> 1> [ >> 1> T=model::Employee >> 1> ] >> 1> c:\XXX\data-model\src\employee.cpp(17) : see reference to >> class template instantiation 'odb::object_traits' being compiled >> 1> with >> 1> [ >> 1> T=model::Employee >> 1> ] >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(104): error C2146: syntax error : >> missing ',' before identifier 'pointer_type' >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(104): error C2065: 'pointer_type' >> : undeclared identifier >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(105): error C2955: >> 'odb::access::object_factory' : use of class template requires >> template argument list >> 1> c:\XXX\libodb-2.0.1\odb\traits.hxx(17) : see declaration >> of 'odb::access::object_factory' >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2146: syntax error : >> missing ';' before identifier 'const_pointer_type' >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C3254: >> 'odb::object_traits' : class contains explicit override >> 'const_pointer_type' but does not derive from an interface that >> contains the function declaration >> 1> with >> 1> [ >> 1> T=model::Employee >> 1> ] >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2838: >> 'const_pointer_type' : illegal qualified name in member declaration >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C4430: missing type >> specifier - int assumed. Note: C++ does not support default-int >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2602: >> 'odb::object_traits::const_pointer_type' is not a member of a base >> class of 'odb::object_traits' >> 1> with >> 1> [ >> 1> T=model::Employee >> 1> ] >> 1> c:\XXX\libodb-2.0.1\odb\traits.hxx(119) : see declaration >> of 'odb::object_traits::const_pointer_type' >> 1> with >> 1> [ >> 1> T=model::Employee >> 1> ] >> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2868: >> 'odb::object_traits::const_pointer_type' : illegal syntax for >> using-declaration; expected qualified-name >> 1> with >> 1> [ >> 1> T=model::Employee >> 1> ] >> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== >> ---8<--- >> >> Any idea what I'm doing wrong here? >> >> -- >> Oded > > > > -- > Oded -- Oded From boris at codesynthesis.com Thu Aug 30 09:25:18 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 30 09:08:27 2012 Subject: [odb-users] Support more then one database vendor in a single application? In-Reply-To: References: Message-ID: Hi Oded, Oded Arbel writes: > I still want to expose the model classes themselves, so that the > application can say things like: > vector employees = Employee::getAll(); > for (vector::iterator it = employees.begin(); it != > employees.end(); ++it) > it->employer->processSalary(*it); > > Where Employee and Employer are the model classes used in ODB, and > getAll() and processSalary() are business logic methods on these > classes. > > I don't want to have the application compile against ODB headers > because that causes VC++ to freak out. It should work fine - unless I > use ODB datatypes like odb::nullable, which I need to represent my > model correctly, and at which point application code start seeing > libodb headers and I get export warnings. That is very strange since libodb itself is built as a DLL and includes all the necessary export/import machinery. Can you show the errors/warnings you are getting? Better yet, can you create a test solution that reproduces this problem? Boris From boris at codesynthesis.com Thu Aug 30 09:37:42 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 30 09:20:53 2012 Subject: [odb-users] Re: Self persisting objects? In-Reply-To: References: Message-ID: Hi Oded, Oded Arbel writes: > libodb-2.0.1\odb\database.ixx(49): error C2440: 'initializing' : > cannot convert from 'model::Employee *' to 'const object_pointer &' If you look at that line, there is a helpful comment preceding it that reads: // The passed pointer should be the same or implicit-convertible // to the object pointer. This way we make sure the object pointer // does not assume ownership of the passed object. // So what most likely happens is you are using a smart pointer (e.g., shared_ptr) as an object pointer. If that's the case then you may want to use the shared_from_this (or similar) machinery to get the shared pointer from this. Also note that the distinction between persisting via object pointer and via reference only comes into play if you are using sessions (if object pointer is not the raw pointer then by- reference persist() won't add the object to the session). So if you are not planning to use sessions, then you can instead replace: s_db->persist(this); With: s_db->persist(*this); > The implementation of Employee::persist() could be pretty trivial > (assuming someone knows how to initialize a database connection. I'm > going to leave that as an exercise to the user and assume an already > inited static field): > > void Employee::persist() { > odb::transaction t(s_db->begin()); > s_db->persist(this); > t.commit(); > } Just a side note: a better design might be to leave it to the caller of Employee::persist() to create the transaction. This way the caller will be able to persist several objects at once: Employee e1, e2; odb::transaction t (db->begin ()); e1.persist (); e2.persist (); t.commit (); The added benefit of this approach is that you can get the database from the current transaction without having to store it in a static field or similar: void Employee::persist() { odb::transaction& t (odb::transaction::current ()); odb::database& db (t.database ()); db.persist (*this); } Boris From oded at geek.co.il Thu Aug 30 12:14:39 2012 From: oded at geek.co.il (Oded Arbel) Date: Thu Aug 30 12:14:50 2012 Subject: [odb-users] Re: Self persisting objects? In-Reply-To: References: Message-ID: On Thu, Aug 30, 2012 at 4:37 PM, Boris Kolpackov wrote: > Oded Arbel writes: >> libodb-2.0.1\odb\database.ixx(49): error C2440: 'initializing' : >> cannot convert from 'model::Employee *' to 'const object_pointer &' > > So what most likely happens is you are using a smart pointer [...] Not in this specific piece of code - its just a "this" pointer. s_db is a smart pointer though - does it matter? > [...] So if > you are not planning to use sessions, then you can instead > replace: > > s_db->persist(this); > > With: > > s_db->persist(*this); I changed it as you said and it looks to be working fine now. I'm not using sessions, but its something that I might want to look into in the future (possibly as an optimization), and I'm a bit confused regarding why is there a difference in the behavior of "this" dereferencing in regard to it being held by a smart pointer or not. > Just a side note: a better design might be to leave it to the caller > of Employee::persist() to create the transaction. This way the caller > will be able to persist several objects at once: > [...] > The added benefit of this approach is that you can get the database > from the current transaction without having to store it in a static > field or similar: > > void Employee::persist() { > odb::transaction& t (odb::transaction::current ()); > odb::database& db (t.database ()); > db.persist (*this); > } That is very interesting - I'll have to consider that in the future, but in the mean time I'm trying to complete a basic implementation before doing more complex things :-) -- Oded From oded at geek.co.il Thu Aug 30 12:19:22 2012 From: oded at geek.co.il (Oded Arbel) Date: Thu Aug 30 12:19:31 2012 Subject: [odb-users] Support more then one database vendor in a single application? In-Reply-To: References: Message-ID: On Thu, Aug 30, 2012 at 4:25 PM, Boris Kolpackov wrote: > Oded Arbel writes: >> I don't want to have the application compile against ODB headers >> because that causes VC++ to freak out. It should work fine - unless I >> use ODB datatypes like odb::nullable, which I need to represent my >> model correctly, and at which point application code start seeing >> libodb headers and I get export warnings. > > That is very strange since libodb itself is built as a DLL and > includes all the necessary export/import machinery. Well... what I was trying to do, is to build a single DLL that bundles both libodb, libodb- and my model, so I can have only 1 DLL that needs to be run-time loaded. It may be that I defined the LIBODB*STATIC* pre-processor definitions incorrectly in my setup. :-/ > Can you show the errors/warnings you are getting? Better yet, > can you create a test solution that reproduces this problem? Currently I reverted to getting everything compiled statically into the application (with support only for MS-SQL in this build). When I get my business logic working properly, I'll re-visit this issue and let you know what's up with this. -- Oded From boris at codesynthesis.com Fri Aug 31 07:15:38 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Aug 31 06:58:40 2012 Subject: [odb-users] Re: Self persisting objects? In-Reply-To: References: Message-ID: Hi Oded, Oded Arbel writes: > > So what most likely happens is you are using a smart pointer [...] > > Not in this specific piece of code - its just a "this" pointer. I mean your persistent class (Employee) uses a smart pointer as its object pointer (normally specified with the 'pointer' pragma, the --default-pointer ODB compiler option, or if you are using Boost or Qt smart-pointer profiles). See Section 3.2, "Object and View Pointers" for details. > I changed it as you said and it looks to be working fine now. I'm not > using sessions, but its something that I might want to look into in > the future (possibly as an optimization), and I'm a bit confused > regarding why is there a difference in the behavior of "this" > dereferencing in regard to it being held by a smart pointer or not. If your persistent class uses a smart pointer, say, shared_ptr, then initializing it from a reference that was passed to persist() (which is needed in order to enter this object into the session) is a bad idea. Think what would happen if that reference is already managed by another shared_ptr instance: void my_persist (Employee& r) { db.persist (r); // Initializing another shared_ptr from &r // is bad news. } shared_ptr p (new Employee (...)); my_persist (*p); That's why if you are using smart pointers, persist() will enter the object into the session only if you pass the smart pointer: db.persist (p); If you need to convert 'this' to a shared_ptr, look into the shared_from_this mechanism. Boris From andrew at nelless.net Fri Aug 31 07:49:35 2012 From: andrew at nelless.net (Andrew Nelless) Date: Fri Aug 31 08:34:09 2012 Subject: [odb-users] std::array doesn't work with BYTEA Message-ID: Hi, I haven't checked 2.1.0a, but I've noticed std::array doesn't work with Postgres BYTEA types in 2.0.1. This seems like a notable omission feature given that it's the clean C++11 replacement for char[N], which is supported. Cheers, Andrew From boris at codesynthesis.com Fri Aug 31 08:56:28 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Aug 31 08:39:30 2012 Subject: [odb-users] std::array doesn't work with BYTEA In-Reply-To: References: Message-ID: Hi Andrew, Andrew Nelless writes: > I haven't checked 2.1.0a, but I've noticed std::array doesn't > work with Postgres BYTEA types in 2.0.1. > > This seems like a notable omission feature given that it's the clean > C++11 replacement for char[N], which is supported. Yes, this is still on my TODO list for 2.1.0. Boris From candy.chiu.ad at gmail.com Fri Aug 31 10:52:18 2012 From: candy.chiu.ad at gmail.com (Candy Chiu) Date: Fri Aug 31 10:52:26 2012 Subject: [odb-users] Can odb be used without touching the domain object files? Message-ID: Hi, I'd like to add db capability to a project without modifying the existing .h's. Is there another way to achieve mapping in this case? Thanks. Candy From hugirat at gmail.com Fri Aug 31 17:20:26 2012 From: hugirat at gmail.com (Yihya Hugirat) Date: Fri Aug 31 17:20:34 2012 Subject: [odb-users] odb and QT Message-ID: Hi all, how to use odb with qt in qt creator. thank you.