From bhartsb at gmail.com Tue May 1 15:04:33 2012 From: bhartsb at gmail.com (B Hart) Date: Tue May 1 15:04:42 2012 Subject: [odb-users] Re: Can one use ODB with Classes generated by XSD? In-Reply-To: References: Message-ID: Hello Boris, I'm re-visiting this thread since ODB now supports MS SQL and I'm at a place where I might be able to use ODB, and my requirements have changed . Particularly I no longer have the need to map my schema into an existing DB that doesn't match the schema well. That is I'm going to create a DB that matches the Schema. I've used CodeSynthesis XSD to generate classes for a set of schemas that happen to be nicely hierarchical. Essentially the XSDs define the elements for patient care records. Each record has up to ~550 elements divided into ~23 subsections/categories. Elements in the subsections have all the different cardinalities. For example, elements relating to adminstering a medication are defined in a complex element with cardinality sequence (since multiple medications might be administered to the same patient, or the same medication given at different times). As an evaluation exercise I generated a DB schema from the XSDs using Altova's XMLSpy. It generated a set of tables very reflective of the organization of the XML Schemas as well as the element constraints. I'm wondering if I similarly relied on ODB to generate the tables if it would produce a similar DB schema, as well as the constraints based on the element types? Haven't tried it yet. Also, I'm wondering if item #2 below has been implemented? I have written a program that with excellent help from XSD generated classes reads in patient records in an XML file, validates the XML, and checks various business rules and generates a report. At the point after validation has occurred and Business Rules are checked and pass, the data is ready to put into the DB. It would be nice if I could use ODB to generate the Schema and make it happen with just a few lines of code (similar to how easy it is with XSD to read in a complex schema and serialize it out again.). Thanks in advance for your comments. On Wed, Jul 27, 2011 at 7:17 AM, Boris Kolpackov wrote: > Hi Brian, > > B Hart writes: > > > Where you say "(those can be placed into a separate file and included > into > > the ODB compilation with the --odb-epilogue option)." do you mean the > > xsd-generated classes with pragmas? > > XSD-generated classes do not have any pragmas (XSD doesn't know anything > about ODB). So you will need to add those pragmas yourself, which can be > placed into a separate file (we call it a "mapping" file) and "added" > to the ODB compilation process (when you compile the XSD-generated header) > using the --odb-epilogue option. > > > > So hypothetically, if I decided to create a whole new DB (based on the > XML > > Schema and using ODB), how would I best use the XSD-generated classes > with > > ODB to do this? Will ODB create a complete DB from the XSD-generated > > output? > > No, as I explained above, you will need to "tell" ODB how to map the > XSD-generated classes to the database, just as you would do for hand- > written code. ODB has no idea which XSD-generated classes should be > objects, which should be value types, which attribute/element is the > object id, etc. Only you can decide such aspects of the mapping. > > There will be other difficulties as well. Here are a few from the > top of my head: > > 1. All data members in the XSD-generated classes are protected which > makes them inaccessible to ODB. To overcome this, you could post- > process the XSD-generated header with a script and replace > 'protected:' with 'public:'. Alternatively, we can add an option > to XSD to generate data members public. > > 2. XSD uses wrapper templates for 'one' and 'optional' members. ODB > will not know how to "unwrap" them without some help from your > side (value_traits). We are currently working on the 'wrapper' > concept for ODB which will make handling this much easier. > > 3. You will need an id member for every object class. This may > or may not be a problem in your case. Support for objects > without an explicit object id is also on our TODO list. > > Boris > From bhartsb at gmail.com Tue May 1 19:35:02 2012 From: bhartsb at gmail.com (B Hart) Date: Tue May 1 19:35:11 2012 Subject: [odb-users] libodb-mysql-1.8.0 and MSVS Message-ID: I downloaded libodb-mysql-1.8.0 and loaded the solution into MSVS 2010. Tried building and I'm getting path include errors. I downloaded and built libodb-1.8.0 with no issues. For example the following include is not properly found:#include Some of these files seem to be in the libodb-1.8.0 folders. Thanks. From boris at codesynthesis.com Wed May 2 04:20:19 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed May 2 04:16:59 2012 Subject: [odb-users] ODB 2.0.0 released Message-ID: Hi, We have released ODB 2.0.0. Besides major new features, this release also includes a few backwards-incompatible changes (thus the major version increment; see below for details). The NEWS file entries for this release are as follows: * Support for C++11. The newly supported C++11 standard library components include: - std::unique_ptr as object pointer or value wrapper - odb::lazy_unique_ptr lazy counterpart - std::shared_ptr/weak_ptr as object pointer or value wrapper - odb::lazy_shared_ptr/lazy_weak_ptr lazy counterparts - support for array, forward_list, and unordered containers - connection factory can be passed to the database constructor as std::unique_ptr instead of std::auto_ptr The ODB compiler now recognizes the --std option. Valid values for this option are 'c++98' (default) and 'c++11'. In the runtime libraries the C++11 support is header-only which means that the same build of a runtime library can be used in both the C++98 and C++11 modes. On UNIX, the tests and examples can be compiled in the C++11 mode by passing the necessary options to turn the C++ compiler into this mode (e.g., -std=c++0x GCC option). On Windows, the tests and examples are always built in the C++11 mode with VC++ 10 and later. The new 'c++11' example in the odb-examples package shows ODB support for some of the C++11 features. * Support for polymorphism. Now a persistent class hierarchy can be declared polymorphic which makes it possible to persist, load, update, erase, and query objects of derived classes using their base class interfaces. For more information, refer to Chapter 8, "Inheritance" in the ODB manual as well as the 'inheritance/polymorphism' example in the odb-examples package. * Support for composite object ids. Now a composite value type can be used to declare an object id member. For more information, refer to Section 7.2.1, "Composite Object Ids" in the ODB manual as well as the 'composite' example in the odb-examples package. * Support for the NULL value semantics for composite values. For more information, refer to Section 7.3, "Pointers and NULL Value Semantics" in the ODB manual. * New schema format (--schema-format), 'separate', allows the generation of the schema creation code into a separate C++ source file (called '-schema.cxx' by default). This value is primarily useful if you want to place the schema creation functionality into a separate program or library. * New namespace-level pragmas: table, pointer. The table pragma specifies the table prefix that is added to table names for all the persistent classes inside a namespace. The pointer pragma specifies the default pointer type to be used for persistent classes and views inside a namespace. For more information, refer to Section 12.5.1, "pointer" and Section 12.5.2, "table" in the ODB manual. * Session support is now optional and is disabled by default. This is a backwards-incompatible change. Session support can be enabled on the per class basis or at the namespace level using the new session pragma. It can also be enabled by default for all the persistent classes using the --generate-session ODB compiler option. Thus, to get the old behavior where all the objects were session-enabled, simply add --generate-session to your ODB compiler command line. For more information, refer to Chapter 10, "Session" in the ODB manual. * The semantics of the database operations callbacks has changed with respect to object const-ness. This is a backwards-incompatible change. Now the callback function for the *_persist, *_update, and *_erase events is always called on the constant object reference while for the *_load events -- always on the unrestricted reference. For more information, refer to Section 12.1.7, "callback" in the ODB manual. * New function, transaction::reset(), allows the reuse of the same transaction instance to complete several database transactions. For more information, refer to Section 3.4, "Transactions" in the ODB manual. * New exception, odb::session_required, is thrown when ODB detects that correctly loading a bidirectional object relationship requires a session but one is not used. For more information, refer to Section 6.2, "Bidirectional Relationships" in the ODB manual. Additionally, this release includes a number of bug fixes and performance improvements in the database-specific runtimes. We have also added GCC 4.7 and Clang 3.0 to the list of compilers that we use for testing each release. Specifically, the ODB compiler has been updated to be compatible with with the GCC 4.7 series plugin API. For the complete list of compilers that were used to test this release, refer to the ODB Platforms and Compilers page: http://www.codesynthesis.com/products/odb/platforms.xhtml With this release we are also introducing a change to the ODB licensing terms. In addition to all the licensing options we currently have (open source and commercial proprietary licenses) we now offer a free proprietary license for small object models. This license allows you to use ODB in a proprietary (closed-source) application free of charge and without any of the GPL restrictions provided that the amount of the generated database support code does not exceed 10,000 lines. The ODB compiler now includes the --show-sloc command line option that can be used to show the amount of code being generated. For more information on the free proprietary license, including a Q&A section, refer to the ODB Licensing page: http://www.codesynthesis.com/products/odb/license.xhtml A more detailed discussion of these features and changes can be found in the following blog post: http://www.codesynthesis.com/~boris/blog/2012/05/02/odb-2-0-0-released/ Source code and pre-compiled binary packages for this release are available from the ODB download page: http://www.codesynthesis.com/products/odb/download.xhtml SHA1 checksums for the files in this release are as follows: 4717e5294249f5bde1e77d9476dd6bc4370a0045 libodb-2.0.0.tar.bz2 45cc815f5dd62f07598d60df46365d6f04b5783a libodb-2.0.0.tar.gz 273ddc2e11880671200a0a70f62a4835a7d90827 libodb-2.0.0.zip c86f8fa7af2fa74906930ef5333fad62ecd2c728 libodb-boost-2.0.0.tar.bz2 cab3b75d9ed01c875587ad93d204b76b42f1baa8 libodb-boost-2.0.0.tar.gz 057c55221968cc5d7999bf91a0efb35d86cf91e9 libodb-boost-2.0.0.zip dd954b23014697216004e3e484949df78b2112d0 libodb-mssql-2.0.0.tar.bz2 47d99b8840c71f6ca757e620476438c96037b53c libodb-mssql-2.0.0.tar.gz 2c619caa50770fa41dc24433326419fbda7c8fe9 libodb-mssql-2.0.0.zip 7b3b7c2bfe3f28156d9c66165f370b401524504f libodb-mysql-2.0.0.tar.bz2 ee439e87b8012a334584e10bfc2597af4c37f218 libodb-mysql-2.0.0.tar.gz 9e54aa15ed3828298143fb4a2f0eaefaac1f9095 libodb-mysql-2.0.0.zip 127df380417db376ff631f6d9e591fa7278c4638 libodb-oracle-2.0.0.tar.bz2 27d538aa3b2eac3bd204a3a9f4948e559af8c8d8 libodb-oracle-2.0.0.tar.gz 6bdd121b694785cc5524b17dc35e73da78917a09 libodb-oracle-2.0.0.zip b24559ecd2bd6a90bc28a219c862c84c90e81add libodb-pgsql-2.0.0.tar.bz2 a765e5f4df9181725159e56f31f37b7749469334 libodb-pgsql-2.0.0.tar.gz d42721db3b39b94d700411d4bd2e8a3c96e3982d libodb-pgsql-2.0.0.zip 685312510e6c2f7afdda1d22503647681bd09489 libodb-qt-2.0.0.tar.bz2 1dc3b697e41f5aa628a7353ec7b03ae6ed13c716 libodb-qt-2.0.0.tar.gz 2babed81882d5384ac4179e5183a31a8d09eb1e7 libodb-qt-2.0.0.zip f76fb3082c66848cc975701c3543a5dab86e3fb4 libodb-sqlite-2.0.0.tar.bz2 89d06be0a237252a4b7823f6b06adf340c61325d libodb-sqlite-2.0.0.tar.gz 3689d4b76430588f1ca9a7efed5ee5ccc64f83a8 libodb-sqlite-2.0.0.zip 377c8c611ca26cacf786b7b90176e99f34779773 odb-2.0.0-i686-linux-gnu.tar.bz2 49fb83e4ba77d1017675a0ee3486590d43c79bd9 odb-2.0.0-i686-macosx.tar.bz2 a1132d7f2fa6e475330fcf69dc959f6f6a76b994 odb-2.0.0-i686-solaris.tar.bz2 34b7cff972077dbe130d5863cd948db74935c519 odb-2.0.0-i686-windows.zip 4930618dba6fcd3dec704d09870e56b8332f9343 odb-2.0.0-sparc-solaris.tar.bz2 52ff18392acc3df4298c1f307ce2def055c372bc odb-2.0.0.tar.bz2 f7580043b7999dbb1bd0634e5bdc118ba8edee25 odb-2.0.0.tar.gz 68e66b77eb65c5bc99e1d6f59c3637970e507f10 odb-2.0.0-x86_64-linux-gnu.tar.bz2 87852c635bf43c7f346cce4fdcdd4b6e336a7e52 odb-2.0.0.zip 462082a175ab9c0e114fdf33312ce79fba3441b1 odb-examples-2.0.0.tar.bz2 dbef881b493fbc5ec0a51225c39405e82c136750 odb-examples-2.0.0.tar.gz b4d7fb39cb1c62630cbc42ebea41c0484f21e881 odb-examples-2.0.0.zip e81dc9df679046b01caa7600cf1a8df4e62e16f1 odb-tests-2.0.0.tar.bz2 9474c1d8c787485eaa3a82755207d4e96d32a76a odb-tests-2.0.0.tar.gz e1e3c05a96f691ec5f8ba427d711bc24677239be odb-tests-2.0.0.zip Enjoy, Boris From boris at codesynthesis.com Wed May 2 10:25:53 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed May 2 10:22:36 2012 Subject: [odb-users] libodb-mysql-1.8.0 and MSVS In-Reply-To: References: Message-ID: Hi Brian, B Hart writes: > I downloaded libodb-mysql-1.8.0 and loaded the solution into MSVS 2010. > Tried building and I'm getting path include errors. I downloaded and built > libodb-1.8.0 with no issues. For example the following include is not > properly found: #include > > Some of these files seem to be in the libodb-1.8.0 folders. The INSTALL file that comes with libodb-mysql says that it expects the libodb (and libmysqlclient) header and import library directories to be in the VC++ Directories Include and Library search lists. See this file (and the one in libodb) for details. Boris From boris at codesynthesis.com Wed May 2 10:39:16 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed May 2 10:35:58 2012 Subject: [odb-users] Use ODB In-Reply-To: <1335787671.15241.YahooMailNeo@web113601.mail.gq1.yahoo.com> References: <1335773097.37075.YahooMailNeo@web113617.mail.gq1.yahoo.com> <1335787671.15241.YahooMailNeo@web113601.mail.gq1.yahoo.com> Message-ID: Hi Khaldon, 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 khaldon hmesheh writes: > I have got the result on the Dos screen which I saved in the attached > file, but I wonder why I didn't have a database file with the name > (odb_test.db) as mentioned in the file (sqlite.option) after the I > have run the examples. The default database file in sqlite.options is C:\Temp\odb_test.db. If you haven't changed it and C:\Temp exists, then you should see that file there after successfully running the examples. Boris From yo at miguelrevilla.com Thu May 3 07:06:03 2012 From: yo at miguelrevilla.com (=?UTF-8?Q?Miguel_Revilla_Rodr=C3=ADguez?=) Date: Thu May 3 07:06:11 2012 Subject: [odb-users] Undefined symbol with GCC 4.7.0 Message-ID: Hi, This is my first post so let me a small OT to thank you for this great piece of software. Now, I've compiled odb 2.0.0 with gcc 4.7.0 and everything went fine while compiling, but execution has this outcome: (person.h is the one from the Hello World example): $ odb -d mysql --generate-query person.h cc1plus: error: cannot load plugin /usr/bin/odb.so /usr/bin/odb.so: undefined symbol: _Z20ggc_round_alloc_sizem $ gcc --version gcc (GCC) 4.7.0 20120414 (prerelease) Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. The distribution is arch linux and, aparently, al required dependencies are in. Any clues? Thans a lot. From boris at codesynthesis.com Thu May 3 07:28:03 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu May 3 07:24:46 2012 Subject: [odb-users] Undefined symbol with GCC 4.7.0 In-Reply-To: References: Message-ID: Hi Miguel, Miguel Revilla Rodr?guez writes: > This is my first post so let me a small OT to thank you for this great > piece of software. Thanks, I am glad you like it! > Now, I've compiled odb 2.0.0 with gcc 4.7.0 and everything went fine > while compiling, but execution has this outcome: > > (person.h is the one from the Hello World example): > > $ odb -d mysql --generate-query person.h > cc1plus: error: cannot load plugin /usr/bin/odb.so > /usr/bin/odb.so: undefined symbol: _Z20ggc_round_alloc_sizem We ran into a similar issue ourselves. Apparently, GCC 4.7 uses a C++ compiler instead of C to build itself. One consequence of this change is that all the symbols become mangled. In 2.0.0 we addressed this by including plugin headers as extern "C" for GCC 4.6 and earlier and as C++ for GCC 4.7 and later. > $ gcc --version > gcc (GCC) 4.7.0 20120414 (prerelease) Perhaps it is the prerelease part that's causing the problem. ODB builds and runs fine with the final GCC 4.7.0 on my Debian box. To verify this, can you check the contents of the bversion.h header in the plugin include directory. To find out its location, run: g++ --print-file-name=plugin The bversion.h file should be in the include/ subdirectory. On my Debian box with GCC 4.7.0 it looks like this: #define BUILDING_GCC_MAJOR 4 #define BUILDING_GCC_MINOR 7 #define BUILDING_GCC_PATCHLEVEL 0 #define BUILDING_GCC_VERSION (BUILDING_GCC_MAJOR * 1000 + BUILDING_GCC_MINOR) If it has something other than 7 for BUILDING_GCC_MINOR, then that would be a problem and upgrading to the final release should fix it (you will need to re-build ODB though). Boris From boris at codesynthesis.com Thu May 3 10:19:54 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu May 3 10:16:39 2012 Subject: [odb-users] Re: Can one use ODB with Classes generated by XSD? In-Reply-To: References: Message-ID: Hi Brian, B Hart writes: > As an evaluation exercise I generated a DB schema from the XSDs using > Altova's XMLSpy. It generated a set of tables very reflective of the > organization of the XML Schemas as well as the element constraints. I'm > wondering if I similarly relied on ODB to generate the tables if it would > produce a similar DB schema, as well as the constraints based on the > element types? Haven't tried it yet. ODB will generate a database schema according to how you map XSD- generated classes to objects, values, relationships, containers, etc. In fact, XML schemas that I normally see (hierarchical, deeply nested, container-in-container-in-container-... kind) don't match the canonical relational model (i.e., a model that an experienced DBA would design) very well. So I am quite surprised you are happy with a database schema generated by XMLSpy without any "mapping" input from your side. And that's also why I am quite skeptical that we can support a fully- automatic XSD->C++->DB mapping, without any user input. To illustrate my point, consider this fairly typical XML and schema (based on the library example from XSD): XML: The Master and Margarita Mikhail Bulgakov War and Peace Leo Tolstoy Schema: How would we map something like this to a database? Is 'name' an object or a value (i.e., do names get their own table or are part of another table)? In case of a name, it is probably a value type. Answering the same question for 'author' is trickier (seeing that there could be multiple books by the same author, it should probably be an object). 'book' is most definitely an object. And 'catalog' probably doesn't have any representation in the database at all! Here is the database schema that I would design for this object model: CREATE TABLE author ( first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, recommends VARCHAR(255) NULL, PRIMARY KEY (first_name, last_name), CONSTRAINT recommends_fk FOREIGN KEY (recommends) REFERENCES book (id))); CREATE TABLE book ( id VARCHAR(255) NOT NULL PRIMARY KEY, title TEXT NOT NULL); CREATE TABLE book_author ( book_id VARCHAR(255) NOT NULL, author_first_name VARCHAR(255) NOT NULL, author_last_name VARCHAR(255) NOT NULL, CONSTRAINT book_fk FOREIGN KEY (book_id) REFERENCES book (id)), CONSTRAINT author_fk FOREIGN KEY (author_first_name, author_last_name) REFERENCES author (first_name, last_name))); Does it resemble the XML schema? Not really. In fact, XML and schema that would resemble this database schema more closely would look along these lines: XML: Mikhail Bulgakov Leo Tolstoy The Master and Margarita MB War and Peace LT Schema: I see schemas like the first one all the time and like the second one -- not much. > I have written a program that with excellent help from XSD generated classes > reads in patient records in an XML file, validates the XML, and checks > various business rules and generates a report. At the point after > validation has occurred and Business Rules are checked and pass, the data is > ready to put into the DB. It would be nice if I could use ODB to generate > the Schema and make it happen with just a few lines of code (similar to how > easy it is with XSD to read in a complex schema and serialize it out > again.). The point of the above exercise is to show that I don't think we can come up with an auto-magical solution which will take an XML schema, generate C++ classes, and map them to the database, all without your DBA swearing at you in the end (for the all the right reasons) ;-). Instead, the generated C++ classes will have to manually and carefully be mapped to the database. > Also, I'm wondering if item #2 below has been implemented? Yes, wrappers and the NULL value semantics are supported. Boris From danielpeterjames at gmail.com Thu May 3 20:50:25 2012 From: danielpeterjames at gmail.com (Daniel James) Date: Thu May 3 20:50:55 2012 Subject: [odb-users] weak_ptr and default pointer type Message-ID: Hi Sorry, this question is a bit basic :) Is it possible to have the following sort of relationship with the default pointer type? #pragma db object pointer(*) class A { ... std::weak_ptr b; ... } #pragma db object pointer(*) class B { ... std::shared_ptr a; ... } I tried the above and a compile time error points to the following in the generated code: // If a compiler error points to the line below, then // it most likely means that a pointer used in a member // cannot be initialized from an object pointer. // o.a = ptr_traits::pointer_type ( db->load< obj_traits::object_type > (id)); It's not explicit in the docs that this is not possible but I suppose it is a consequence of std::weak_ptr's constructors? Daniel From boris at codesynthesis.com Fri May 4 05:34:44 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri May 4 05:31:31 2012 Subject: [odb-users] weak_ptr and default pointer type In-Reply-To: References: Message-ID: Hi Daniel, Daniel James writes: > Is it possible to have the following sort of relationship with the default > pointer type? > > #pragma db object pointer(*) > class A { > ... > std::weak_ptr b; > ... > } > #pragma db object pointer(*) > class B { > ... > std::shared_ptr a; > ... > } > > I tried the above and a compile time error points to the following in the > generated code: > > // If a compiler error points to the line below, then > // it most likely means that a pointer used in a member > // cannot be initialized from an object pointer. > // > o.a = ptr_traits::pointer_type ( > db->load< obj_traits::object_type > (id)); > > It's not explicit in the docs that this is not possible but I suppose it is > a consequence of std::weak_ptr's constructors? Chapter 6, "Relationships" in the ODB Manual, first paragraph has this sentence: "Any supported smart pointer can be used in a data member as long as it can be explicitly constructed from the canonical object pointer. For example, we can use weak_ptr if the object pointer is shared_ptr." The reason why the above won't work is because weak_ptr cannot be initialized with a raw pointer (only with shared_ptr). Boris From aakmail at mail.ru Fri May 4 06:13:24 2012 From: aakmail at mail.ru (=?UTF-8?B?QWxleGFuZGVyIEtvbmlu?=) Date: Fri May 4 06:43:04 2012 Subject: [odb-users] Brief-case model with ODB Message-ID: Hi, How about brief-case model with ODB? Typical use case of an application I designing looks like this: a user connects to database with his personal notebook and retrieves neccessary data. Then the user saves the data on local storage (notebook HDD) and close the application (turns off the notebook). ?Next time, for instance at home, the user works with the data. Then the user must synchronize his work with database.? IMHO, simplest way to implement this scenario is serialisation of the odb::session object to any local storage (like XML or binary file), but there is no any related functionality in the odb::session class. Are there other solutions for this scenario with ODB? Thanks, Alex From elizabeta.petreska at gmail.com Mon May 7 03:24:45 2012 From: elizabeta.petreska at gmail.com (elizabeta petreska) Date: Mon May 7 03:24:53 2012 Subject: [odb-users] support for boost types Message-ID: Hi Are the following boost types supported by odb, and if not ,will they be anytime soon ? 1) boost::multi-index 2) boost::scoped_ptr 3) boost::variant 4) boost::optional From boris at codesynthesis.com Mon May 7 04:22:52 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon May 7 04:19:46 2012 Subject: [odb-users] support for boost types In-Reply-To: References: Message-ID: Hi Elizabeta, elizabeta petreska writes: > Are the following boost types supported by odb, and if not ,will they be > anytime soon ? > > 1) boost::multi-index This container is not yet supported but should be easy to add. If you are interested, I can implement something for you to try in the next couple of days. > 2) boost::scoped_ptr scoped_ptr can be used right now to manage lifetime of objects that have the raw pointer as their object pointer (the default). For example: boost::scoped_ptr p (db.load (id)); However, scoped_ptr cannot be used as an object pointer since it is not copy-constructible or movable (i.e., we cannot return it from a function, unlike, say, shared_ptr, unique_ptr, or auto_ptr). Finally, boost::scoped_ptr can be used as a data member in a class, for example: class person { ... boost::scoped_ptr middle_name_; }; While this usage is not yet supported by ODB, it is trivial to add (this is really an oversight mainly because this usage is not very common). Which use-case are you interested in? > 3) boost::variant This one is tricky since there is no portable, underlying SQL type to map it to. See this recent thread for various ways of storing variant in the database with ODB: http://www.codesynthesis.com/pipermail/odb-users/2012-April/000494.html > 4) boost::optional This is supported. See Section 19.3, "Optional Library" in the ODB manual: http://www.codesynthesis.com/products/odb/doc/manual.xhtml#19.3 Boris From boris at codesynthesis.com Mon May 7 04:38:14 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon May 7 04:35:10 2012 Subject: [odb-users] Brief-case model with ODB In-Reply-To: References: Message-ID: Hi Alexander, Alexander Konin writes: > How about brief-case model with ODB? Typical use case of an application > I designing looks like this: a user connects to database with his personal > notebook and retrieves neccessary data. Then the user saves the data on > local storage (notebook HDD) and close the application (turns off the > notebook). Next time, for instance at home, the user works with the data. > Then the user must synchronize his work with database. > > IMHO, simplest way to implement this scenario is serialisation of the > odb::session object to any local storage (like XML or binary file), > but there is no any related functionality in the odb::session class. > Are there other solutions for this scenario with ODB? To me, saving the data to a local relational database (e.g., SQLite) sounds like the most natural way to support this. This way, most of the application logic won't need to know whether it is working with a local or remote database. The catch here is that ODB doesn't yet have multi-database support ( i.e., the ability to store the same object to multiple database implementations from the same application). But this support is coming soon. Serializing objects to a binary or XML format will probably work as well. I agree, currently, there is no way to iterate over the objects in the session. While we can easily add this support, I am not sure it will be very usable. If you look at the data members in the odb::session class, you will see that the objects are stored in a typeless form (all you have to identify what kind of object it is is std::type_info). In that sense, it might be easier to derive all your objects from a common base class and then use a callback (see Section 12.1.7) to insert all the objects into a custom map. But if you think that the ability to iterate over a session will be helpful, let me know, and I we will add it. Boris From boris at codesynthesis.com Mon May 7 04:49:20 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon May 7 04:46:13 2012 Subject: [odb-users] ODB compiler source 2.0.1 bugfix released Message-ID: Hi, A new bugfix release for the ODB compiler source package is now available. It fixes an issue with GCC 4.7 which can be built in either C or C++ mode. The original 2.0.0 source package was only working with GCC built in the C++ mode. This bugfix addresses this limitation. You only need to upgrade if (1) you are trying to build the ODB compiler from source code yourself (as opposed to using a binary package) and (2) you are using GCC 4.7 and experiencing problems running the ODB compiler. For more information on this issue, refer to the following mailing list thread: http://www.codesynthesis.com/pipermail/odb-users/2012-May/000531.html You can download the package from the ODB download page: http://www.codesynthesis.com/products/odb/download.xhtml SHA1 checksums for the files in this release are as follows: 4f085cff02b43773d6c4aab9734f8dc99cf857f5 odb-2.0.1.tar.bz2 5e1d697040b8a0002be340b6af8c4646825a2ec6 odb-2.0.1.tar.gz 07004ad9b57d4a14e0ed2e87303a33d7db42d0dd odb-2.0.1.zip Boris From bhartsb at gmail.com Wed May 9 19:49:39 2012 From: bhartsb at gmail.com (B Hart) Date: Wed May 9 19:49:49 2012 Subject: [odb-users] Re: Can one use ODB with Classes generated by XSD? In-Reply-To: References: Message-ID: Hi Boris, Sorry about the late response, I was put on to some other tasks. I looked over the two XSD/XML examples you provided. In the first example, there is a catalog of books where (potentially) a book can have may authors and an author many books (many to many, but in this case with attribute "recommends" it is unidirectional 1:1). In the second example it is a catalog of both books and authors (a little strange), with the same attribute "recommends" expressing a unidirectional 1:1 relationship. (BTW: In the first example, shouldn't "recommends" be an element (minOccurs = 0 maxOccurs = unbounded), since this really isn't Metadata? ) The XML schema I'm working with seems closer to your second example. The DB Schema auto-generated by XMLSpy is definitely not perfect, but with a little minor cleanup should be 3N form. There is a Patient Care record (1patient = 1 record), and each record is divided into a number of sections, and the relationships between elements are hierarchical in one direction (down the tree) with some 1 to many relationships. I've tried to see where there might be relationships between elements in different sections, but there seem to be few. Data inserted is immutable. So maybe I just got lucky or I haven't explored deeply enough yet. I do know that it was very quick for me to generate the tables and then use Mapforce to create an extraction and load (not much transforming). I'd like to use ODB, but it seems like it is going to take a lot of time to create all the mappings. I understand it might be be difficult to auto-generate an acceptable DB Schema in the majority of instances, but would even a poor DB Schema and mapping (automatically generated) be a better starting point than none at all (especially when there are going to be many tables)??? What do you think about the idea of having a pragma that could be used to remove the mappings in sections of XSD generated classes that weren't found to auto generate correctly a portion of the DB schema??? >>Yes, wrappers and the NULL value semantics are supported. Can you point me to any examples showing how wrappers are used? Thanks. On Thu, May 3, 2012 at 7:19 AM, Boris Kolpackov wrote: > Hi Brian, > > B Hart writes: > > > As an evaluation exercise I generated a DB schema from the XSDs using > > Altova's XMLSpy. It generated a set of tables very reflective of the > > organization of the XML Schemas as well as the element constraints. I'm > > wondering if I similarly relied on ODB to generate the tables if it would > > produce a similar DB schema, as well as the constraints based on the > > element types? Haven't tried it yet. > > ODB will generate a database schema according to how you map XSD- > generated classes to objects, values, relationships, containers, etc. > In fact, XML schemas that I normally see (hierarchical, deeply nested, > container-in-container-in-container-... kind) don't match the canonical > relational model (i.e., a model that an experienced DBA would design) > very well. So I am quite surprised you are happy with a database schema > generated by XMLSpy without any "mapping" input from your side. And > that's also why I am quite skeptical that we can support a fully- > automatic XSD->C++->DB mapping, without any user input. > > To illustrate my point, consider this fairly typical XML and schema > (based on the library example from XSD): > > XML: > > > > The Master and Margarita > > > Mikhail > Bulgakov > > > > > > War and Peace > > > Leo > Tolstoy > > > > > > > Schema: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > How would we map something like this to a database? Is 'name' an object > or a value (i.e., do names get their own table or are part of another > table)? In case of a name, it is probably a value type. Answering the > same question for 'author' is trickier (seeing that there could be > multiple books by the same author, it should probably be an object). > 'book' is most definitely an object. And 'catalog' probably doesn't > have any representation in the database at all! > > Here is the database schema that I would design for this object model: > > CREATE TABLE author ( > first_name VARCHAR(255) NOT NULL, > last_name VARCHAR(255) NOT NULL, > recommends VARCHAR(255) NULL, > > PRIMARY KEY (first_name, last_name), > CONSTRAINT recommends_fk FOREIGN KEY (recommends) REFERENCES book (id))); > > CREATE TABLE book ( > id VARCHAR(255) NOT NULL PRIMARY KEY, > title TEXT NOT NULL); > > CREATE TABLE book_author ( > book_id VARCHAR(255) NOT NULL, > author_first_name VARCHAR(255) NOT NULL, > author_last_name VARCHAR(255) NOT NULL, > > CONSTRAINT book_fk FOREIGN KEY (book_id) REFERENCES book (id)), > CONSTRAINT author_fk > FOREIGN KEY (author_first_name, author_last_name) > REFERENCES author (first_name, last_name))); > > Does it resemble the XML schema? Not really. In fact, XML and schema that > would resemble this database schema more closely would look along these > lines: > > XML: > > > > > > > Mikhail > Bulgakov > > > > > > Leo > Tolstoy > > > > > > > The Master and Margarita > MB > > > > War and Peace > LT > > > > > > Schema: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I see schemas like the first one all the time and like the second one -- > not much. > > > I have written a program that with excellent help from XSD generated > classes > > reads in patient records in an XML file, validates the XML, and checks > > various business rules and generates a report. At the point after > > validation has occurred and Business Rules are checked and pass, the > data is > > ready to put into the DB. It would be nice if I could use ODB to > generate > > the Schema and make it happen with just a few lines of code (similar to > how > > easy it is with XSD to read in a complex schema and serialize it out > > again.). > > The point of the above exercise is to show that I don't think we can come > up with an auto-magical solution which will take an XML schema, generate > C++ classes, and map them to the database, all without your DBA swearing > at you in the end (for the all the right reasons) ;-). > > Instead, the generated C++ classes will have to manually and carefully > be mapped to the database. > > > Also, I'm wondering if item #2 below has been implemented? > > Yes, wrappers and the NULL value semantics are supported. > > Boris > From khaldon_hmesheh at yahoo.com Wed May 9 11:40:50 2012 From: khaldon_hmesheh at yahoo.com (khaldon hmesheh) Date: Thu May 10 11:59:53 2012 Subject: [odb-users] Sqlite Message-ID: <1336578050.26773.YahooMailNeo@web113612.mail.gq1.yahoo.com> Hello, I don't know while I am compiling my project all information related to database in database.hxx file turned inactive (I use vs2008 on Windows XP)? and I got the following error (error C2065: 'db' : undeclared identifier) what should I do to overcome this error. Please see the attached file. Best regards Khaldon -------------- next part -------------- A non-text attachment was scrubbed... Name: database.PNG Type: image/png Size: 138650 bytes Desc: not available Url : http://codesynthesis.com/pipermail/odb-users/attachments/20120509/88998996/database-0001.png From boris at codesynthesis.com Thu May 10 12:08:11 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu May 10 12:05:01 2012 Subject: [odb-users] Sqlite In-Reply-To: <1336578050.26773.YahooMailNeo@web113612.mail.gq1.yahoo.com> References: <1336578050.26773.YahooMailNeo@web113612.mail.gq1.yahoo.com> Message-ID: Hi Khaldon, Please don't send image attachements to this mailing list, as discussed in the posting guidelines: http://www.codesynthesis.com/support/posting-guidelines.xhtml khaldon hmesheh writes: > I don't know while I am compiling my project all information related > to database in database.hxx file turned inactive (I use vs2008 on > Windows XP) and I got the following error (error C2065: 'db' : > undeclared identifier) what should I do to overcome this error. If you are using database.hxx from one of the examples, then you need to define one of the DATABASE_XXX macros (e.g., DATABASE_SQLITE) to select the specific database you would like to use. There are several ways you can do this. You can do it for the whole project in the project settings (see the Preprocessor tab in VC++). You can also add #define DATABASE_SQLITE at the beginning of the database.hxx file itself. Boris From boris at codesynthesis.com Thu May 10 12:14:10 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu May 10 12:11:01 2012 Subject: [odb-users] Re: ODB In-Reply-To: <18508549F1E38440AB3EB326C2D9BF8D06364BB279@fitdewhms501> References: <18508549F1E38440AB3EB326C2D9BF8D06364BB279@fitdewhms501> Message-ID: Hi Gennadiy, In the future please send technical questions like this to the odb-users mailing list (CC'ed). See the posting guidelines for details: http://www.codesynthesis.com/support/posting-guidelines.xhtml Pochtar, Gennadiy (FIT) writes: > does your ODB software supports UNICODE charset, i.e. is there a way > to use UNICODE chars in ODB queries? Yes, UNICODE is supported though specifics depend on the database that you are using. For example, with MS SQL Server you can do: std::wstring name (L"John"); result r = db->query (query::first_name == name); With other databases (e.g., Oracle) you can pass UTF-8-encoded std::string. Which database are you using? Boris From boris at codesynthesis.com Fri May 11 04:37:58 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri May 11 04:34:49 2012 Subject: [odb-users] Re: ODB In-Reply-To: <18508549F1E38440AB3EB326C2D9BF8D06364BB2B6@fitdewhms501> References: <18508549F1E38440AB3EB326C2D9BF8D06364BB279@fitdewhms501> <18508549F1E38440AB3EB326C2D9BF8D06364BB2B6@fitdewhms501> Message-ID: Gennadiy, Please keep your replies CC'ed to the odb-users mailing list so that others who may have similar questions in the future can benefit from the answers. Pochtar, Gennadiy (FIT) writes: > > Which database are you using? > > Our future product must support MS SQL (2005 and later), Oracle and > SQLite (for test cases). Now I am looking for some "good" ORM, ideally > something like Hibernate, although must not be so powerful. Doesn't > matter what kind of product: open source or commercial one. UNICODE > and dynamic queries support are key issues. > > > result r = db->query (query::first_name == name); > > And what should I do with (first like N'John%'), where first is UNICODE? You can do something like this: std::wstring pattern (L"John%"); result r = db->query ("first_name LIKE" + query::_val (pattern)); The general idea here is that for constructs that are not part of the C++-integrated query language you can always drop down to the database native query language. The good news is that at this level ODB still takes care of converting query parameters from C++ to the database system format using the query::_val() and query::_ref() functions. In the above example we use this to make ODB pass a UNICODE string to the database. See Chapter 4, "Querying the Database" for more information: http://www.codesynthesis.com/products/odb/doc/manual.xhtml#4 Boris From khaldon_hmesheh at yahoo.com Mon May 14 04:28:37 2012 From: khaldon_hmesheh at yahoo.com (khaldon hmesheh) Date: Mon May 14 04:28:46 2012 Subject: [odb-users] help Message-ID: <1336984117.35686.YahooMailNeo@web113602.mail.gq1.yahoo.com> hi, I have written the following code and I want to try how the relations work. Here is the class and relations definitions ship--->generalCharacteristic; ship<---->assembly assembly--->dreiDPoint #ifndef SHIP_HXX #define SHIP_HXX #include #include #include // std::size_t #include #include #include using std::tr1::shared_ptr; using odb::tr1::lazy_shared_ptr; using odb::tr1::lazy_weak_ptr; // The following bidirectional relationships are used: // // one-to-many : ship <--> Assembly // to-one : ship --> generalCharacteristics //to-one : assembly --> 3DPoint // Forward declarations. // class ship; class generalCharacteristic; class assembly; class dreiDPoint; typedef std::vector > assemblies; enum type {barge, bargeForDeckLoading, bargeForLiquefiedGas, bargForOil}; #pragma db object class generalCharacteristic { public: ? generalCharacteristic (const float& lpp? ?) ? : lpp_ (lpp) { } /////length between the perpendicular float lpp () const { return lpp_; } void lpp (float lpp) { lpp_ = lpp; ?} private: friend class odb::access; generalCharacteristic () {} #pragma db id auto unsigned long id_; float lpp_; ? }; #pragma db object class assembly { public: typedef ::ship ship_type; typedef ::dreiDPoint dreiDPoint_type; assembly (float weight, ? lazy_shared_ptr cog) ? : weight_ (weight), cog_ (cog) { } float weight() const { return weight_; } void weight (float weight) { weight_=weight; } // Ship. // const lazy_weak_ptr& ship () const { return ship_; } void ship (lazy_weak_ptr ship) { ship_ = ship; } // 3D Point of this COG. // const lazy_shared_ptr& cog () const { return cog_; } void cog (lazy_shared_ptr cog) { cog_ = cog; ? } ? private: friend class odb::access; assembly () {} float weight_; #pragma db id auto unsigned long assemId_; #pragma db value_not_null inverse (assemblies_) lazy_weak_ptr ship_; #pragma db null lazy_shared_ptr cog_; }; #pragma db object class dreiDPoint { public: ? dreiDPoint (float xValue) ? : xValue_ (xValue) { } /////x coordinate of the point float xValue () const { return xValue_; } void xValue (float xValue) { xValue_ = xValue; } ? private: friend class odb::access; dreiDPoint () {} #pragma db id auto unsigned long id_; float xValue_; ? }; #pragma db object class ship { public: typedef ::generalCharacteristic generalCharacteristic_type; typedef ::assemblies assembly_type; ship (unsigned int imoId, unsigned short buildingYear, type shipType, const std::string& name, lazy_shared_ptr generalCharacteristic) : imoId_ (imoId), buildingYear_ (buildingYear), shipType_ (shipType),name_(name), generalCharacteristic_ (generalCharacteristic) { } unsigned int imoId () const { return imoId_; } void imoId (unsigned int imoId) { imoId_=imoId; } unsigned short buildingYear () const { return buildingYear_; } void buildingYear (unsigned short buildingYear) { buildingYear_=buildingYear; } const std::string& name () const { return name_; } void name (std::string name) { name_=name; } type shipType () const { return shipType_; } void shipType (type shipType) { shipType_=shipType; } // Assemblies of this ship const assembly_type& assemblies () const { return assemblies_; } assembly_type& assemblies () { return assemblies_; } // General Charachteristics of this ship. // lazy_shared_ptr generalCharacteristic () const { return generalCharacteristic_; } void generalCharacteristic (lazy_shared_ptr generalCharacteristic) { generalCharacteristic_ = generalCharacteristic; } private: friend class odb::access; ship () {} #pragma db id auto unsigned long id_; unsigned int imoId_; unsigned short buildingYear_; std::string name_; type shipType_; #pragma db value_null unordered assembly_type assemblies_; #pragma db not_null lazy_shared_ptr generalCharacteristic_; }; #endif // SHIP_HXX /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// and I have written something like the following code in driver: #include // std::auto_ptr #include #include #include #include #include "database.hxx" // create_database #include "ship.hxx" #include "ship-odb.hxx" using namespace std; using namespace odb::core; int main (int argc, char* argv[]) { try { auto_ptr db (create_database (argc, argv)); unsigned long karam1_id, karam2_id; // Create a few persistent objects. // { ? shared_ptr gc (new generalCharacteristic (100.2)); ? shared_ptr dp (new dreiDPoint (5.2)); ? shared_ptr assem (new assembly (1200,dp)); shared_ptr karam (new ship (1500,1995,barge,"Karam1",gc)); // Set the inverse side of the ship-assemblies relationship. // karam->assemblies().push_back(assem); // Set the ship-generalCharacteristic relationship. // karam->generalCharacteristic() = gc; transaction t (db->begin ()); db->persist (gc); db->persist (dp); db->persist (assem); karam1_id = db->persist (karam); t.commit (); } ? { session s; transaction t (db->begin()); shared_ptr p (db->load (karam1_id)); ? cout<<" general charac: "<generalCharacteristic_->lpp_< References: <1336984117.35686.YahooMailNeo@web113602.mail.gq1.yahoo.com> Message-ID: Hi Khaldon, khaldon hmesheh writes: > shared_ptr p (db->load (karam1_id)); > cout<<" general charac: "<generalCharacteristic_->lpp_< > I got the following error messages: > > error C2248: 'ship::generalCharacteristic_' : cannot access private member > declared in class 'ship' > > error C2248: 'generalCharacteristic::lpp_' : cannot access private member > declared in class 'generalCharacteristic' This doesn't really have anything to do with ODB: in your code you try to access data members that are private. Perhaps you should use (public) accessors instead: p->generalCharacteristic ()->lpp () Boris From boris at codesynthesis.com Mon May 14 13:39:19 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon May 14 13:39:30 2012 Subject: [odb-users] Re: Can one use ODB with Classes generated by XSD? In-Reply-To: References: Message-ID: Hi Brian, B Hart writes: > I understand it might be be difficult to auto-generate an acceptable DB > Schema in the majority of instances, but would even a poor DB Schema and > mapping (automatically generated) be a better starting point than none at > all (especially when there are going to be many tables)? It might seem so, but in the long run, I don't think it will (generally, we try to avoid designing tools that have short-term benefits with long- term problems, even if it is very tempting sometimes). You mentioned above that the "DB Schema auto-generated by XMLSpy is definitely not perfect, but with a little minor cleanup should be 3N form." The problem with this approach is that you will have to keep manually "fixing-up" the schema (plus the generated C++ code, if we were to support this in XSD) every time the XML schema changes. This is the example of the "short-term benefits with long-term problems" approach I am talking about. The approach that I have in mind would require you to providing initial mapping (e.g., which classes are objects, which ones are values, which attributes/elements are object ids, etc). This might require some upfront time investment. However, down the road, provided the future schema changes are not too radical, this mapping shouldn't take much effort to maintain. It should definitely be easier than fixing-up generated database and C++ code. Boris From niermann at informatik.uni-tuebingen.de Tue May 15 11:27:30 2012 From: niermann at informatik.uni-tuebingen.de (niermann@informatik.uni-tuebingen.de) Date: Tue May 15 11:27:40 2012 Subject: [odb-users] Problem connecting a mysql server Message-ID: <463081b7cd1113a9b03e4e73634b88c5.squirrel@imap.informatik.uni-tuebingen.de> Dear Boris, I get a segmentation fault when I try to run the odb-tests (checked for versions 1.8.0 and 2.0.0 with appropriate libs) on a mysql-server: ./driver --options-file ../../db.options BEGIN INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) COMMIT BEGIN SELECT `auto_object`.`id`,`auto_object`.`str` FROM `auto_object` WHERE `auto_object`.`id`=? ROLLBACK ./../../tester: line 35: 28986 Segmentation fault (core dumped) ./driver --options-file "$top_builddir/db.options" > test.out FAIL: ../../tester ============================================ 1 of 1 test failed Please report to odb-users@codesynthesis.com ============================================ I looked up the mysql-logs: 120515 16:44:49 479 Connect niermann@bsnode02.Informatik.Uni-Tuebingen.De on PIBI5 479 Query select @@version_comment limit 1 479 Query DROP TABLE IF EXISTS `auto_auto_only` 479 Query DROP TABLE IF EXISTS `auto_object` 479 Query CREATE TABLE `auto_object` ( `id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, `str` TEXT NOT NULL) ENGINE=InnoDB 479 Query CREATE TABLE `auto_auto_only` ( `id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB 479 Quit 120515 16:44:50 480 Connect niermann@bsnode02.Informatik.Uni-Tuebingen.De on PIBI5 480 Query begin 480 Prepare INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) 480 Reset stmt 480 Execute INSERT INTO `auto_object` (`id`,`str`) VALUES (0,0) 480 Reset stmt 480 Execute INSERT INTO `auto_object` (`id`,`str`) VALUES (0,0) 480 Reset stmt 480 Execute INSERT INTO `auto_object` (`id`,`str`) VALUES (0,0) 480 Query commit 480 Query begin 480 Prepare SELECT `auto_object`.`id`,`auto_object`.`str` FROM `auto_object` WHERE `auto_object`.`id`=? 480 Reset stmt 480 Execute SELECT `auto_object`.`id`,`auto_object`.`str` FROM `auto_object` WHERE `auto_object`.`id`=0 After the SELECT statement the segfault occurs. I think even the INSERT statements are not working right, since the inserted strings are all empty. I tried it for a 64bit linux machine with a 2.6.18-238.5.1.el5 kernel and compiled the odb-tests with gcc (GCC) 4.6.1. May this be related to the old kernel? Since I'm not sure what causes the segmentation fault, do you have any hints for me what I could try to get further information? With kind regards, Peter Niermann From boris at codesynthesis.com Tue May 15 14:05:13 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue May 15 14:05:23 2012 Subject: [odb-users] Problem connecting a mysql server In-Reply-To: <463081b7cd1113a9b03e4e73634b88c5.squirrel@imap.informatik.uni-tuebingen.de> References: <463081b7cd1113a9b03e4e73634b88c5.squirrel@imap.informatik.uni-tuebingen.de> Message-ID: Hi Peter, niermann@informatik.uni-tuebingen.de writes: > ./driver --options-file ../../db.options > BEGIN > INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) > INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) > INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) > COMMIT > BEGIN > SELECT `auto_object`.`id`,`auto_object`.`str` FROM `auto_object` WHERE > `auto_object`.`id`=? > ROLLBACK > ./../../tester: line 35: 28986 Segmentation fault (core dumped) I assume you modified the driver to trace the SQL statement execution. Based on that last ROLLBACK line, I think that an exception is thrown (this ROLLBACK is caused by the transaction object's destructor being called when the stack is unwound). Can you run gdb on the driver and core file (the actual executable is .libs/lt-driver) and send the stack trace (once in gdb, run the 'bt' command): gdb .libs/lt-driver core > I tried it for a 64bit linux machine with a 2.6.18-238.5.1.el5 kernel and > compiled the odb-tests with gcc (GCC) 4.6.1. I assume you installed unixODBC-2.3.1 and Microsoft's Native Client driver for Linux? See this blog post for more information: http://www.codesynthesis.com/~boris/blog/2011/12/02/microsoft-sql-server-odbc-driver-linux/ > May this be related to the old kernel? No, I don't think it is related to the kernel version. One thing that would be helpful to know is the version of SQL Server you are connecting to. Boris From niermann at informatik.uni-tuebingen.de Wed May 16 06:50:33 2012 From: niermann at informatik.uni-tuebingen.de (niermann@informatik.uni-tuebingen.de) Date: Wed May 16 06:50:43 2012 Subject: [odb-users] Problem connecting a mysql server Message-ID: <8b37f2dc5d3266dbfa2a73769f5021d8.squirrel@imap.informatik.uni-tuebingen.de> Hello Boris, thank you for your help so far. Now that you told me the right driver I was able to trace the stack. On 15.05.2012 20:05, Boris Kolpackov wrote: > Hi Peter, > > niermann@informatik.uni-tuebingen.de writes: > >> ./driver --options-file ../../db.options >> BEGIN >> INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) >> INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) >> INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) >> COMMIT >> BEGIN >> SELECT `auto_object`.`id`,`auto_object`.`str` FROM `auto_object` WHERE >> `auto_object`.`id`=? >> ROLLBACK >> ./../../tester: line 35: 28986 Segmentation fault (core dumped) > I assume you modified the driver to trace the SQL statement execution. > Based on that last ROLLBACK line, I think that an exception is thrown > (this ROLLBACK is caused by the transaction object's destructor being > called when the stack is unwound). > > Can you run gdb on the driver and core file (the actual executable is > .libs/lt-driver) and send the stack trace (once in gdb, run the 'bt' > command): > > gdb .libs/lt-driver core > Here comes the stacktrace: #0 mysql_send_query (mysql=0x0, query=0x2ada3e9aaa2f "rollback", length=8) at /export/home2/tmp/cteam/bs/connector-c-64bit/src/mysql-connector-c-6.0.2/libmysql/client.c:2899 #1 0x00002ada3f35f339 in mysql_real_query (mysql=0x0, query=0x2ada3e9aaa2f "rollback", length=8) at /export/home2/tmp/cteam/bs/connector-c-64bit/src/mysql-connector-c-6.0.2/libmysql/client.c:2910 #2 0x00002ada3f360879 in mysql_query (mysql=0x0, query=0x2ada3e9aaa2f "rollback") at /export/home2/tmp/cteam/bs/connector-c-64bit/src/mysql-connector-c-6.0.2/libmysql/libmysql.c:790 #3 0x00002ada3e9a541d in odb::mysql::transaction_impl::rollback (this=0xc18e9e0) at transaction-impl.cxx:91 #4 0x00002ada3ebbac7d in ~transaction (this=0x7fff09383430) at transaction.cxx:24 #5 0x0000000000000003 in ?? () #6 0x00000000004024f6 in odb::database::load (this=, id=) at /home/niermann/libodb-2.0.0/odb/database.txx:64 #7 0x000000000c1a81a0 in ?? () #8 0x0000000000402b79 in main (argc=3, argv=) at driver.cxx:58 Current language: auto; currently c I used the mysql-connector-c-6.0.2-linux-glibc2.3-x86-64bit as mysql-library. >> I tried it for a 64bit linux machine with a 2.6.18-238.5.1.el5 kernel and >> compiled the odb-tests with gcc (GCC) 4.6.1. > I assume you installed unixODBC-2.3.1 and Microsoft's Native Client driver > for Linux? See this blog post for more information: > > http://www.codesynthesis.com/~boris/blog/2011/12/02/microsoft-sql-server-odbc-driver-linux/ As far as I understand the unixODBC lib is only needed when connecting to a Microsoft-SQL server. We are running a linux MySQL server: Server version: 5.1.38-log Source distribution Since the odb-tests are working perfect when run on an ubuntu machine which connects to the same database I don't think it is an issue with the database server. The mysql server listens on the port 3307 since it is our instance for testing. On the standard port runs the productive server. May this be problematic? Another point is, that Qt querries to the same database are working correctly. Further help is much apprechiated. Peter >> May this be related to the old kernel? > No, I don't think it is related to the kernel version. One thing that would > be helpful to know is the version of SQL Server you are connecting to. > > Boris From boris at codesynthesis.com Wed May 16 07:59:42 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed May 16 07:59:56 2012 Subject: [odb-users] Problem connecting a mysql server In-Reply-To: <8b37f2dc5d3266dbfa2a73769f5021d8.squirrel@imap.informatik.uni-tuebingen.de> References: <8b37f2dc5d3266dbfa2a73769f5021d8.squirrel@imap.informatik.uni-tuebingen.de> Message-ID: Hi Peter, Sorry about that link for ODBC. For some reason I got the impression that you are using MS SQL Server but now I see it is MySQL. > Here comes the stacktrace: > > [...] Thanks, that's helpful. Can you modify the common/auto/driver.cxx file by replacing this code fragment starting on line 56: auto_ptr o1 (db->load (id1)); auto_ptr o2 (db->load (id2)); auto_ptr o3 (db->load (id3)); With this: try { auto_ptr o1 (db->load (id1)); auto_ptr o2 (db->load (id2)); auto_ptr o3 (db->load (id3)); } catch (const odb::exception& e) { cerr << e.what () << endl; return 1; } catch (const std::exception& e) { cerr << "std: " << e.what () << endl; return 1; } Then re-run the test (i.e., run make check in common/auto/) and let me know what it prints? Boris From niermann at informatik.uni-tuebingen.de Wed May 16 09:54:29 2012 From: niermann at informatik.uni-tuebingen.de (niermann@informatik.uni-tuebingen.de) Date: Wed May 16 09:54:40 2012 Subject: [odb-users] Problem connecting a mysql server Message-ID: <28d4a9cbe8f173905a6c921449926566.squirrel@imap.informatik.uni-tuebingen.de> Hi Boris, I did the modification you suggested and got an 'object not persistent' exception: make check-am make[1]: Entering directory `/nfs/wsi/bs/share/usr/niermann/odb-tests-2.0.0/common/auto' make check-TESTS make[2]: Entering directory `/nfs/wsi/bs/share/usr/niermann/odb-tests-2.0.0/common/auto' ./driver --options-file ../../db.options BEGIN INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) INSERT INTO `auto_object` (`id`,`str`) VALUES (?,?) COMMIT BEGIN SELECT `auto_object`.`id`,`auto_object`.`str` FROM `auto_object` WHERE `auto_object`.`id`=? object not persistent ROLLBACK ./../../tester: line 35: 4896 Segmentation fault (core dumped) ./driver --options-file "$top_builddir/db.options" > test.out FAIL: ../../tester and the stacktrace for this error: #0 mysql_send_query (mysql=0x0, query=0x2ba99bb17a2f "rollback", length=8) at /export/home2/tmp/cteam/bs/connector-c-64bit/src/mysql-connector-c-6.0.2/libmysql/client.c:2899 #1 0x00002ba99c4cc339 in mysql_real_query (mysql=0x0, query=0x2ba99bb17a2f "rollback", length=8) at /export/home2/tmp/cteam/bs/connector-c-64bit/src/mysql-connector-c-6.0.2/libmysql/client.c:2910 #2 0x00002ba99c4cd879 in mysql_query (mysql=0x0, query=0x2ba99bb17a2f "rollback") at /export/home2/tmp/cteam/bs/connector-c-64bit/src/mysql-connector-c-6.0.2/libmysql/libmysql.c:790 #3 0x00002ba99bb1241d in odb::mysql::transaction_impl::rollback (this=0xf7b89e0) at transaction-impl.cxx:91 #4 0x00002ba99bd27c7d in ~transaction (this=0x7fff2bcf1780) at transaction.cxx:24 #5 0x00002ba99c7b5260 in ?? () #6 0x000000317b41cbc0 in _dl_argv_internal () from /lib64/ld-linux-x86-64.so.2 #7 0x000000317b41cbc0 in _dl_argv_internal () from /lib64/ld-linux-x86-64.so.2 #8 0x000000000040295b in main (argc=3, argv=) at driver.cxx:55 Current language: auto; currently c I must add that the string values of the example are not written to the database: mysql> SELECT * FROM auto_object; +----+-----+ | id | str | +----+-----+ | 1 | 0 | | 2 | 0 | | 3 | 0 | +----+-----+ 3 rows in set (0.00 sec) Regards, Peter On 16.05.2012 13:59, Boris Kolpackov wrote: > Hi Peter, > > Sorry about that link for ODBC. For some reason I got the impression > that you are using MS SQL Server but now I see it is MySQL. > >> Here comes the stacktrace: >> >> [...] > Thanks, that's helpful. Can you modify the common/auto/driver.cxx > file by replacing this code fragment starting on line 56: > > auto_ptr o1 (db->load (id1)); > auto_ptr o2 (db->load (id2)); > auto_ptr o3 (db->load (id3)); > > With this: > > try > { > auto_ptr o1 (db->load (id1)); > auto_ptr o2 (db->load (id2)); > auto_ptr o3 (db->load (id3)); > } > catch (const odb::exception& e) > { > cerr << e.what () << endl; > return 1; > } > catch (const std::exception& e) > { > cerr << "std: " << e.what () << endl; > return 1; > } > > Then re-run the test (i.e., run make check in common/auto/) and > let me know what it prints? > > Boris From boris at codesynthesis.com Wed May 16 13:23:46 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed May 16 13:23:55 2012 Subject: [odb-users] Problem connecting a mysql server In-Reply-To: <28d4a9cbe8f173905a6c921449926566.squirrel@imap.informatik.uni-tuebingen.de> References: <28d4a9cbe8f173905a6c921449926566.squirrel@imap.informatik.uni-tuebingen.de> Message-ID: Hi Peter, niermann@informatik.uni-tuebingen.de writes: > I did the modification you suggested and got an 'object not persistent' > exception. This is very strange. My guess is that there is some incompatibility with the MySQL client library you have installed (libmysqlclient) and your distribution. From your kernel version I gather you are using RedHat EL 5 (or CentOS 5). You also mentioned that you use mysql-connector-c-6.0.2-linux-glibc2.3-x86-64bit as the client library. A better option would be to use libmysqlclient that comes with your distribution. Try something like this: yum install mysqlclient16 yum install mysqlclient16-devel If that doesn't work for some reason, then the next best option is to try an RPM from the MySQL download site: http://dev.mysql.com/downloads/mysql/5.1.html Make sure you select RedHat Linux 4 & 5 from the Platform list and then download and install: MySQL-devel-community-5.1.63-1.rhel5.i386.rpm MySQL-shared-community-5.1.63-1.rhel5.i386.rpm Boris From niermann at informatik.uni-tuebingen.de Fri May 18 04:26:47 2012 From: niermann at informatik.uni-tuebingen.de (niermann@informatik.uni-tuebingen.de) Date: Fri May 18 04:26:56 2012 Subject: [odb-users] Problem connecting a mysql server Message-ID: <5dbd83508c4aa7746ba0afc25eb07a0a.squirrel@imap.informatik.uni-tuebingen.de> Hello Boris, thank you so much for your help. Using the distribution specific libmysqlclient finally solved the issue. The tests are running now. Best, Peter On 16.05.2012 19:23, Boris Kolpackov wrote: > Hi Peter, > > niermann@informatik.uni-tuebingen.de writes: > >> I did the modification you suggested and got an 'object not persistent' >> exception. > This is very strange. My guess is that there is some incompatibility > with the MySQL client library you have installed (libmysqlclient) > and your distribution. From your kernel version I gather you are > using RedHat EL 5 (or CentOS 5). You also mentioned that you use > mysql-connector-c-6.0.2-linux-glibc2.3-x86-64bit as the client > library. A better option would be to use libmysqlclient that comes > with your distribution. Try something like this: > > yum install mysqlclient16 > yum install mysqlclient16-devel > > If that doesn't work for some reason, then the next best option is > to try an RPM from the MySQL download site: > > http://dev.mysql.com/downloads/mysql/5.1.html > > Make sure you select RedHat Linux 4 & 5 from the Platform list and > then download and install: > > MySQL-devel-community-5.1.63-1.rhel5.i386.rpm > MySQL-shared-community-5.1.63-1.rhel5.i386.rpm > > Boris From khaldon_hmesheh at yahoo.com Fri May 18 09:10:57 2012 From: khaldon_hmesheh at yahoo.com (khaldon hmesheh) Date: Fri May 18 10:11:12 2012 Subject: [odb-users] Help Message-ID: <1337346657.22955.YahooMailNeo@web113608.mail.gq1.yahoo.com> Hello Boris, I have generated an sqlite database file and I have written something in it, but after I restart my application to do some changes later I can't access my persistent objects within it. It always tells me that no objects when I try to query for them. I have tried to open the database file with Notepad to see some names refer to my stored objects and I found them there, but when I try to get them I couldn't. What should I do to overcome this problem.? Khaldon From meow at xentrea.me Fri May 18 09:24:58 2012 From: meow at xentrea.me (Xentrea) Date: Fri May 18 10:11:14 2012 Subject: [odb-users] PostgreSQL & uuid type Message-ID: Hello! How mapping *char *or *unsigned char* to *uuid* for PostgreSQL database? For example (didn't work) :( typedef std::vector uuid; #pragma db value(uuid) type("UUID") #pragma db object class object { ... uuid id_; // }; Maybe i'm mistaken? Thanks! From boris at codesynthesis.com Fri May 18 10:36:21 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri May 18 10:36:26 2012 Subject: [odb-users] PostgreSQL & uuid type In-Reply-To: References: Message-ID: Hi, Xentrea writes: > How mapping *char *or *unsigned char* to *uuid* for PostgreSQL database? > > For example (didn't work) :( > > typedef std::vector uuid; > #pragma db value(uuid) type("UUID") > > #pragma db object > class object > { > ... > > uuid id_; // > }; At the moment we don't provide a default mapping for Postgres UUID type mainly because there is no single "default" C++ type. Possible options are std::vector<[unsigned] char> and [unsigned] char[16]. std::vector seems a bit wasteful and char[16] could be a bit too low-level (i.e., such a mapping will be difficult to use as an object id). But you can always provide your won mapping. This thread describes the overall procedure in detail: http://www.codesynthesis.com/pipermail/odb-users/2012-March/000482.html For the PostgreSQL UUID type, the traits function signatures are as follows: static void set_value (value_type&, const unsigned char*, bool is_null); static void set_image (unsigned char*, bool& is_null, const value_type&); For example, here is an implementation for std::vector: #include #include #include #include namespace odb { namespace pgsql { template <> class value_traits, id_uuid> { public: typedef std::vector value_type; typedef std::vector query_type; typedef unsigned char* image_type; static void set_value (value_type& v, const unsigned char* i, bool is_null) { if (is_null) v.clear (); else v.assign (i, i + 16); } static void set_image (unsigned char* i, bool& is_null, const value_type& v) { is_null = v.empty (); if (!is_null) { assert (v.size () == 16); std::memcpy (i, &v.front (), 16); } } }; } } Boris From boris at codesynthesis.com Fri May 18 10:45:26 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri May 18 10:45:30 2012 Subject: [odb-users] Unable to load objects after application restart In-Reply-To: <1337346657.22955.YahooMailNeo@web113608.mail.gq1.yahoo.com> References: <1337346657.22955.YahooMailNeo@web113608.mail.gq1.yahoo.com> Message-ID: Khaldon, In the future please use more descriptive subject lines instead of just "Help" as discussed in the posting guidelines: http://www.codesynthesis.com/support/posting-guidelines.xhtml khaldon hmesheh writes: > I have generated an sqlite database file and I have written something > in it, but after I restart my application to do some changes later I > can't access my persistent objects within it. It always tells me that > no objects when I try to query for them. If you are using database.hxx from one of the examples (and I believe you are), then this code by default re-creates the database schema (and deletes all its contents) every time you call create_schema(). See the block of code that starts with the "// Create the database schema..." comment after "#elif defined(DATABASE_SQLITE)". The schema/embedded example in the odb-examples package includes a piece of code that shows how to create the schema only if it doesn't already exist. Boris From crburton at tnsi.com Fri May 18 20:43:05 2012 From: crburton at tnsi.com (Burton, Craig) Date: Fri May 18 20:43:40 2012 Subject: [odb-users] boost date_time link error Message-ID: Hi odb-users, I've never used the Boost libraries before, but I believe that it is necessary to do so in order to utilize the Oracle DATE type. My quick test seems to compile ok, but fails during link: cburton@deep-thought: make odb --database oracle --generate-schema --generate-query --profile boost -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' NPAC.H odb --database oracle --generate-schema --generate-query --profile boost -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' NPA.H odb --database oracle --generate-schema --generate-query --profile boost -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' NPACImage.H g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c loadNetworkSPData.C g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c NPAC-odb.cxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c NPA-odb.cxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c NPACImage-odb.cxx g++ -lodb -lodb-oracle -lboost_date_time loadNetworkSPData.o NPAC-odb.o NPA-odb.o NPACImage-odb.o -o loadNetworkSPData Undefined first referenced symbol in file typeinfo for odb::boost::date_time::special_value NPACImage-odb.o vtable for odb::boost::date_time::special_value NPACImage-odb.o ld: fatal: Symbol referencing errors. No output written to loadNetworkSPData collect2: ld returned 1 exit status make: *** [loadNetworkSPData] Error 1 Any thoughts on what I might be doing wrong? Thank you in advance. Thank you, Craig ________________________________ This e-mail message is for the sole use of the intended recipient(s)and may contain confidential and privileged information of Transaction Network Services. Any unauthorised review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. From boris at codesynthesis.com Sat May 19 01:24:16 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sat May 19 01:24:25 2012 Subject: [odb-users] boost date_time link error In-Reply-To: References: Message-ID: Hi Craig, Burton, Craig writes: > I've never used the Boost libraries before, but I believe that it > is necessary to do so in order to utilize the Oracle DATE type. More precisely, ODB provides a mapping of Oracle data-time types to Boost data_time library (as well as Qt C++ date-time types). But you can always map Oracle date-time types to some other suitable C++ data-time representations if desired (see the 'mapping' example in the odb-examples package for details). Using Boost (or Qt), is probably the easiest way to get started, thought. > My quick test seems to compile ok, but fails during link: > > [...] > > g++ -lodb -lodb-oracle -lboost_date_time loadNetworkSPData.o NPAC-odb.o > NPA-odb.o NPACImage-odb.o -o loadNetworkSPData > > Undefined first referenced > symbol in file > > typeinfo for odb::boost::date_time::special_value NPACImage-odb.o > vtable for odb::boost::date_time::special_value NPACImage-odb.o >From your ld output I gather you are using Solaris. The most likely cause of the above error is that Boost date_time was build with Sun CC wile you are using GCC to build your application. You will need to use the same compiler for both. You can either use Sun CC to build your application (and ODB runtime libraries) or you will need to rebuild Boost using GCC. For more information on how to do this, see the Section 5.3, "Or, Build Custom Binaries" in Boost getting started guide (you will need to use 'gcc' as the toolchain): http://www.boost.org/doc/libs/1_49_0/more/getting_started/unix-variants.html#or-build-custom-binaries Boris From khaldon_hmesheh at yahoo.com Sat May 19 11:12:05 2012 From: khaldon_hmesheh at yahoo.com (khaldon hmesheh) Date: Sat May 19 11:13:13 2012 Subject: [odb-users] Open the generated databse from another application Message-ID: <1337440325.85311.YahooMailNeo@web113619.mail.gq1.yahoo.com> Hello Boris, I have generated one database file (RDBMS sqlite) by one application and I have tried to access this database by another application but I couldn't. It said that no such table. What should I do to get access by another application. Best wishes Khaldon From johannes.lochmann at googlemail.com Sun May 20 08:11:03 2012 From: johannes.lochmann at googlemail.com (Johannes Lochmann) Date: Sun May 20 08:22:25 2012 Subject: [odb-users] Open the generated databse from another application In-Reply-To: <1337440325.85311.YahooMailNeo@web113619.mail.gq1.yahoo.com> References: <1337440325.85311.YahooMailNeo@web113619.mail.gq1.yahoo.com> Message-ID: <4FB8DF57.3080707@googlemail.com> Hello, could you please provide sample code and sample (error) output from your coding attempt? regards, Johannes Am 19.05.12 17:12, schrieb khaldon hmesheh: > > Hello Boris, > > I have generated one database file (RDBMS sqlite) by one application and I have tried to access this database by another application but I couldn't. It said that no such table. What should I do to get access by another application. > > Best wishes > Khaldon > From koraytaylan at gmail.com Mon May 21 03:41:30 2012 From: koraytaylan at gmail.com (Koray Taylan Davgana) Date: Mon May 21 03:42:00 2012 Subject: [odb-users] poco libraries support Message-ID: Hi, I subscribed this list about a week ago and suprised how active it is. I'm on planning phase of a small project and decided to use odb. I'm also kind of new to c++ so most of the time I'm reading docs and trying to compile examples. From the odb docs I know that it supports boost and qt libraries. Boost feels like for more hardcore c++ coders than me. And I don't prefer Qt for licencing options. So I came across POCO c++ libraries( http://pocoproject.org/) and I totally liked it. I need a multithread web server and poco has a special component for it right out of the box. These may sound kind of silly I can guess but as I said I'm new to c++ so even these small bits can save me at least a couple of weeks. I now boost has asio and example3 in it's documents is just what i'm asking. I figured it out how to compile and run it but it feels like a standalone project by itself rather than a simple example. I'm used c# mostly so unified component structure of poco feels more comfortoble for me rather than distributed header files of boost. Anyways long story short, I wanted to ask that is there any plans for poco libraries support for odb? Thanks, Koray. From khaldon_hmesheh at yahoo.com Mon May 21 04:39:45 2012 From: khaldon_hmesheh at yahoo.com (khaldon hmesheh) Date: Mon May 21 04:39:54 2012 Subject: [odb-users] Open the generated databse from another application In-Reply-To: <4FB8DF57.3080707@googlemail.com> References: <1337440325.85311.YahooMailNeo@web113619.mail.gq1.yahoo.com> <4FB8DF57.3080707@googlemail.com> Message-ID: <1337589585.32735.YahooMailNeo@web113615.mail.gq1.yahoo.com> Hello, thanks for your reply. The example (schema\embedded) is very helpful for my case. If I created two projects (I use sqlite and ?MVS2008 on windows XP.? ) ?to store some persons with different names and ages by one application and I store some another persons to the same database from within the second application. If I try to query for all objects from one application I couldn't get the objects created by the second one. This happened although I have only one database file. I feel something strange here. Regards Khaldon ?>Hello, >could you please provide sample code and sample (error) output from your? >coding attempt? >regards, >Johannes Am 19.05.12 17:12, schrieb khaldon hmesheh: > > Hello Boris, > > I have generated one database file (RDBMS sqlite) by one application and I have tried to access this database by another application but I couldn't. It said that no such table. What should I do to get access by another application. > > Best wishes > Khaldon > From boris at codesynthesis.com Mon May 21 04:42:36 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon May 21 04:42:39 2012 Subject: [odb-users] poco libraries support In-Reply-To: References: Message-ID: Hi Koray, Koray Taylan Davgana writes: > Anyways long story short, I wanted to ask that is there any plans for > poco libraries support for odb? By "support" I assume you mean a POCO profile for ODB. POCO is a fairly niche library (you are the first asking about it with regards to ODB) so we currently don't have plans to provide a profile for it. Though if it turns out there is a lot of interest for using ODB with POCO, we can definitely reconsider. Having said that, this doesn't mean that you cannot use POCO with ODB without a profile. I took a look at the examples, and it appears POCO is using std::string for strings as well as the standard containers. This means that simple things will work out of the box. If you want to use more advanced ODB feaures, such as object relationships, or certain database types, such as date-time types, BLOBs, etc., and you want to use the "POCO way" of handling these, only then things will start getting problematic without a POCO profile. Specifically, you won't be able to use POCO smart pointers (AutoPtr and SharedPtr) as object pointers. For completeness, here is the list of mappings that a POCO profile could provide: Buffer BLOB database types Nullable NULL values (similar to odb::nullable & boost::optional) UUID UUID database type DateTime Date-time database types Also note that nothing prevents you from implementing ODB support for any of these components yourself. ODB is very extensible in that sense. In fact, there is no reason a POCO profile cannot be implemented as a third- party library. Though if you are new to C++, then this might be a bit too much ;-). Boris From boris at codesynthesis.com Mon May 21 05:01:57 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon May 21 05:02:01 2012 Subject: [odb-users] Open the generated databse from another application In-Reply-To: <1337589585.32735.YahooMailNeo@web113615.mail.gq1.yahoo.com> References: <1337440325.85311.YahooMailNeo@web113619.mail.gq1.yahoo.com> <4FB8DF57.3080707@googlemail.com> <1337589585.32735.YahooMailNeo@web113615.mail.gq1.yahoo.com> Message-ID: Hi Khaldon, khaldon hmesheh writes: > If I created two projects (I use sqlite and MVS2008 on windows XP.) to > store some persons with different names and ages by one application and > I store some another persons to the same database from within the second > application. If I try to query for all objects from one application I > couldn't get the objects created by the second one. This happened although I > have only one database file. I suggest that you examine the database with the sqlite shell[1]. You can download a precompiled binary for Windows from the SQLite download page[2]. First examine it after the first application has run. You can check which tables are present in the database using this query: SELECT * FROM sqlite_master WHERE type='table'; You can then see which rows are present in each table of interest using this query: SELECT * FROM ; Then you can examine the same database after the second application has run. This time you can confirm that the new rows have been added to this database and to the correct tables. If the new rows are not present, then you second application must be using another database file. If the new rows are present but the old ones are gone, then your second application most likely re-creates the schema in the database (which also deletes all the data). If none of this provides any clues, then you can turn on the SQL statement tracing in your applications (see Section 3.12, "Tracing SQL Statement Execution" in the ODB manual) and make sure that the statements use the correct table names, etc. [1] http://www.sqlite.org/sqlite.html [2] http://www.sqlite.org/download.html Boris From jaroszewski.luk at gmail.com Mon May 21 08:31:07 2012 From: jaroszewski.luk at gmail.com (=?ISO-8859-2?Q?=A3ukasz_Jaroszewski?=) Date: Mon May 21 08:47:33 2012 Subject: [odb-users] not_in_transaction exception with sqlite Message-ID: Hello, I have just started using odb with sqlite database. My problem is that, when I try to use create_schema or db->persist(x) i get an exception: not_in_transaction. odb::transaction t (db.begin ()); db.persist (x); t.commit (); t.has_current() returns true and db.execute("select * from sometabme") returns exactly row count I have in db. So connection Is ok, I think. From boris at codesynthesis.com Mon May 21 11:27:01 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon May 21 11:27:04 2012 Subject: [odb-users] not_in_transaction exception with sqlite In-Reply-To: References: Message-ID: Hi ?ukasz, ?ukasz Jaroszewski writes: > My problem is that, when I try to use create_schema or db->persist(x) > i get an exception: not_in_transaction. > > odb::transaction t (db.begin ()); > db.persist (x); > t.commit (); > > t.has_current() returns true and db.execute("select * from sometabme") > returns exactly row count I have in db. So connection Is ok, I think. Yes, this is very strange, particularly because database::execute() also checks for the current transaction, just like database::persist(). So the fact that you are getting this exception from one but not from the other is particularly strange. The transaction "current" machinery uses TLS, unless threads are disabled. And my only guess is that TLS does not work properly in your configuration for some reason. ODB also tries to use compiler support for TLS, if available, and falls back on the operating system API. So maybe one of these mechanisms is not working as expected. To explore this possibility further, it would be helpful to know which platform you are on, which compiler you are using, as well as if you are doing anything special (e.g., disabled thread support, static linking, etc). Another thing that you can try is build and run one of the examples from the odb-examples package (say, 'hello'). It would be interesting to see if it fails in a similar way. Boris From crburton at tnsi.com Mon May 21 13:01:25 2012 From: crburton at tnsi.com (Burton, Craig) Date: Mon May 21 13:01:55 2012 Subject: [odb-users] boost date_time link error In-Reply-To: References: Message-ID: Hi Boris, Thank you for the suggestion. I rebuilt boost, ensuring that only gcc was used, and again encountered the same link error with my code. I then looked at the odb example code and was surprised to find that the boost example (with the Oracle DATE type) linked *without* error.... This definitely placed the problem squarely in my code. Upon closer inspection in my prototype, I found that I had neglected to add "libodb-boost.so" to LFLAGS! This was the root issue. Once I added that library, the link step completed without error. Thanks for the help! Craig -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Friday, May 18, 2012 10:24 PM To: Burton, Craig Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] boost date_time link error Hi Craig, Burton, Craig writes: > I've never used the Boost libraries before, but I believe that it > is necessary to do so in order to utilize the Oracle DATE type. More precisely, ODB provides a mapping of Oracle data-time types to Boost data_time library (as well as Qt C++ date-time types). But you can always map Oracle date-time types to some other suitable C++ data-time representations if desired (see the 'mapping' example in the odb-examples package for details). Using Boost (or Qt), is probably the easiest way to get started, thought. > My quick test seems to compile ok, but fails during link: > > [...] > > g++ -lodb -lodb-oracle -lboost_date_time loadNetworkSPData.o NPAC-odb.o > NPA-odb.o NPACImage-odb.o -o loadNetworkSPData > > Undefined first referenced > symbol in file > > typeinfo for odb::boost::date_time::special_value NPACImage-odb.o > vtable for odb::boost::date_time::special_value NPACImage-odb.o >From your ld output I gather you are using Solaris. The most likely cause of the above error is that Boost date_time was build with Sun CC wile you are using GCC to build your application. You will need to use the same compiler for both. You can either use Sun CC to build your application (and ODB runtime libraries) or you will need to rebuild Boost using GCC. For more information on how to do this, see the Section 5.3, "Or, Build Custom Binaries" in Boost getting started guide (you will need to use 'gcc' as the toolchain): http://www.boost.org/doc/libs/1_49_0/more/getting_started/unix-variants.html#or-build-custom-binaries Boris This e-mail message is for the sole use of the intended recipient(s)and may contain confidential and privileged information of Transaction Network Services. Any unauthorised review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. From boris at codesynthesis.com Mon May 21 15:58:45 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon May 21 15:58:55 2012 Subject: [odb-users] not_in_transaction exception with sqlite In-Reply-To: References: Message-ID: Hi ?ukasz, In the future please keep your replies CC'ed to the odb-users mailing list so that others who might run into similar problems could benefit. See the posting guidelines for details: http://www.codesynthesis.com/support/posting-guidelines.xhtml ?ukasz Jaroszewski writes: > Thanks for answer. It point me direction and I found problem. > Well, I have linked with odb.lib;odb-sqlite-d.lib. > Changing to odb-d.lib;odb-sqlite-d.lib solves the problem. > It's my fault, but I don't know If there is also in odb. Yes, this makes sense. If your application links to odb.lib and odb-sqlite-d.lib (i.e., one release while the other debug), the process will have two libodb DLLs loaded (odb.dll and odb-d.dll) since odb-sqlite-d.dll links to odb-d.dll. This in turn means that you will end up with two TLS slots for the transaction's "current" value. Naturally, this doesn't end well ;-). Boris From Davide.Anastasia at qualitycapital.com Wed May 30 04:40:14 2012 From: Davide.Anastasia at qualitycapital.com (Davide Anastasia) Date: Wed May 30 04:40:30 2012 Subject: [odb-users] Creation of ODB cache Message-ID: Hi, I'm trying to create a cache of ODB objects: these objects are stored into this map and will be retrieved for the map instead than the database when already available. Does anything like exist already in ODB? Best, 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 boris at codesynthesis.com Wed May 30 05:13:28 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed May 30 05:13:34 2012 Subject: [odb-users] Creation of ODB cache In-Reply-To: References: Message-ID: Hi Davide, Davide Anastasia writes: > I'm trying to create a cache of ODB objects: these objects are stored > into this map and will be retrieved for the map instead than > the database when already available. > > Does anything like exist already in ODB? Yes, it is called session and the key is the object id. One big advantage of the session compared to a custom cache is that it is integrated with the database operations (e.g., persist(), load(), erase(), etc). So, for example, if you call load() and the object is already in the session, then it will be automatically returned without any database access. For more information, see Chapter 10, "Session" in the ODB manual. Boris From Davide.Anastasia at qualitycapital.com Wed May 30 05:41:22 2012 From: Davide.Anastasia at qualitycapital.com (Davide Anastasia) Date: Wed May 30 05:41:48 2012 Subject: [odb-users] Creation of ODB cache In-Reply-To: References: Message-ID: Thanks Boris, I had a look at the manual. I have a few questions on that: 1. can a session object be a member of a class? I'm saying that because my class essentially runs into an std::thread and waits for "updates" to store, starting a transaction every time: void run() { while (1) { // wait Transaction t( ...) ; // load, persist, ? t.commit(); } } 2. how many session object can my application have? Can it make sense to have a session at the beginning of the application as "master" session? 3. If I do a conditional search, is the retrieved object stored in the session? 4. Does session apply to Views? To many questions, I know :) Best, Davide -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: 30 May 2012 10:13 To: Davide Anastasia Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] Creation of ODB cache Hi Davide, Davide Anastasia writes: > I'm trying to create a cache of ODB objects: these objects are stored > into this map and will be retrieved for the map instead > than the database when already available. > > Does anything like exist already in ODB? Yes, it is called session and the key is the object id. One big advantage of the session compared to a custom cache is that it is integrated with the database operations (e.g., persist(), load(), erase(), etc). So, for example, if you call load() and the object is already in the session, then it will be automatically returned without any database access. For more information, see Chapter 10, "Session" in the ODB manual. Boris From boris at codesynthesis.com Wed May 30 10:00:30 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed May 30 10:00:39 2012 Subject: [odb-users] Creation of ODB cache In-Reply-To: References: Message-ID: Hi Davide, Davide Anastasia writes: > 1. can a session object be a member of a class? The session that is currently provided by ODB is per-thread (a pointer to the current session is stored in the TLS). It is also not thread- aware in the sense that a single session cannot be used safely from multiple threads concurrently. However, one can imagine that a shared, thread-aware implementation could be useful for some applications so we could add something like this in the future. So, to answer your question, yes, you can make a session object a member of a class though it will "attach" itself to the thread where the class' constructor is executed, which may or may not be what you want (you can "detach" it from the current and attach it to another thread using the provided "current" API). > I'm saying that because my class essentially runs into an > std::thread and waits for "updates" to store, starting a > transaction every time: > > void run() > { > while (1) > { > // wait > Transaction t( ...) ; > > // load, persist, ? > > t.commit(); > } > } In this case it seems more straightforward to just do: void run() { session s; while (1) { .. } } Unless you plan to restart the thread and want to keep the session's contents. > 2. how many session object can my application have? Can it make sense to > have a session at the beginning of the application as "master" session? I think the above explanation should make this clear now. Currently, you can have one active session per thread. > 3. If I do a conditional search, is the retrieved object stored in the > session? You mean if you execute a query? In that case, yes, if you actual instantiate the object (i.e., dereference the iterator), then yes, the object will be cached. > 4. Does session apply to Views? No, views are not stored in a session (they have no object ids). > To many questions, I know :) No problem. It is always good to understand how people are using (or trying to use) ODB. Boris From crburton at tnsi.com Wed May 30 18:04:31 2012 From: crburton at tnsi.com (Burton, Craig) Date: Wed May 30 18:05:03 2012 Subject: [odb-users] modified polymorphism example trouble... Message-ID: Hi ODB-Users, I am encountering a compilation issue with some 'static' prototyping, in which I am attempting to use the 'polymorphism inheritance' approach. By 'static' prototyping, I am presently attempting only to reproduce (with ODB and Oracle) an existing class structure that currently exists in an object-oriented database. I was able to recreate the issue with a subtle modification of the polymorphism example in 2.0. Please excuse the verbosity of this email; I wasn't sure how to convey the problem without showing all of the details... The nature of the problem stems from my goal to keep all class definition files separate from one another. For instance, in the polymorphism example, the person and employee class definitions both exist in the same file. I am able to build the example files successfully in the unmodified form in an environment outside the example file hierarchy using this Makefile: CC=g++ ODB_INCLUDES=-I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' CFLAGS=-DDATABASE_ORACLE $(ODB_INCLUDES) -c LFLAGS=-lodb -lodb-oracle -lodb-boost -lboost_date_time ODB=odb ODBFLAGS=--database oracle --generate-schema --generate-query --profile boost/date-time all: driver driver: driver.o employee.o employee-odb.o $(CC) $(LFLAGS) driver.o employee.o employee-odb.o \ -o driver driver.o: driver.cxx employee.hxx employee.cxx employee-odb.cxx $(CC) $(CFLAGS) driver.cxx employee-odb.cxx: employee.hxx $(ODB) $(ODBFLAGS) $(ODB_INCLUDES) employee.hxx employee-odb.o: employee.hxx employee-odb.cxx $(CC) $(CFLAGS) employee-odb.cxx employee.o: employee.cxx employee.hxx $(CC) $(CFLAGS) employee.cxx clean: rm -rf *.o *-odb.cxx *-odb.hxx *-odb.ixx *.sql driver ================================================ cburton@deep-thought: make odb --database oracle --generate-schema --generate-query --profile boost/date-time -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' employee.hxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c driver.cxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c employee.cxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c employee-odb.cxx g++ -lodb -lodb-oracle -lodb-boost -lboost_date_time driver.o employee.o employee-odb.o \ -o driver So the unmodified code compiles successfully. However, when I attempt to break the employee files into person.hxx, person.cxx, employee.hxx and employee.cxx, I see the same behavior as in my separate, static prototype. Here are the files: Person.hxx: #ifndef PERSON_HXX #define PERSON_HXX #include #include #pragma db object polymorphic class person { public: person (const std::string& first, const std::string& last) : first_ (first), last_ (last) { } const std::string& first () const { return first_; } const std::string& last () const { return last_; } virtual ~person () = 0; virtual void print () = 0; protected: friend class odb::access; person () {} #pragma db id auto unsigned long id_; std::string first_; std::string last_; }; #endif // PERSON_HXX ================================================ person.cxx: #include #include "person.hxx" using namespace std; person:: ~person () { } ================================================ employee.hxx: // file : inheritance/polymorphism/employee.hxx // copyright : not copyrighted - public domain #ifndef EMPLOYEE_HXX #define EMPLOYEE_HXX #include #include #include "person.hxx" // moved to its own file /* #pragma db object polymorphic class person ... std::string last_; }; */ #pragma db object class employee: public person { public: employee (const std::string& first, const std::string& last, bool temporary) : person (first, last), temporary_ (temporary) { } (everything from here down is unmodified) ================================================ employee.cxx // file : inheritance/polymorphism/employee.cxx // copyright : not copyrighted - public domain #include #include "employee.hxx" using namespace std; // moved to its own file //person:: //~person () //{ //} void employee:: print () { cout << first_ << ' ' << last_ << (temporary_ ? " temporary " : " permanent ") << "employee" << endl; } void contractor:: print () { cout << first_ << ' ' << last_ << ' ' << email_ << " contractor" << endl; } ================================================ Makefile: CC=g++ ODB_INCLUDES=-I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' CFLAGS=-DDATABASE_ORACLE $(ODB_INCLUDES) -c LFLAGS=-lodb -lodb-oracle -lodb-boost -lboost_date_time ODB=odb ODBFLAGS=--database oracle --generate-schema --generate-query --profile boost/date-time all: driver driver: driver.o person.o person-odb.o employee.o employee-odb.o $(CC) $(LFLAGS) driver.o person.o person-odb.o employee.o employee-odb.o \ -o driver driver.o: driver.cxx person.hxx person.cxx person-odb.cxx employee.hxx employee.cxx employee-odb.cxx $(CC) $(CFLAGS) driver.cxx person-odb.cxx: person.hxx $(ODB) $(ODBFLAGS) $(ODB_INCLUDES) person.hxx employee-odb.cxx: employee.hxx $(ODB) $(ODBFLAGS) $(ODB_INCLUDES) employee.hxx person-odb.o: person.hxx person-odb.cxx $(CC) $(CFLAGS) person-odb.cxx employee-odb.o: employee.hxx employee-odb.cxx $(CC) $(CFLAGS) employee-odb.cxx person.o: person.cxx person.hxx $(CC) $(CFLAGS) person.cxx employee.o: employee.cxx employee.hxx $(CC) $(CFLAGS) employee.cxx clean: rm -rf *.o *-odb.cxx *-odb.hxx *-odb.ixx *.sql driver Lastly, here is the result of 'make': cburton@deep-thought: make odb --database oracle --generate-schema --generate-query --profile boost/date-time -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' person.hxx odb --database oracle --generate-schema --generate-query --profile boost/date-time -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' employee.hxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c driver.cxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c person.cxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c person-odb.cxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c employee.cxx g++ -DDATABASE_ORACLE -I/usr/local/odb/include -I/usr/local/oracle/instantclient_11_2/sdk/include -I/usr/local/boost/boost_1_49_0 -I'.' -c employee-odb.cxx In file included from /usr/local/odb/include/odb/oracle/polymorphic-object-statements.hxx:23:0, from employee-odb.cxx:27: /usr/local/odb/include/odb/oracle/simple-object-statements.hxx: In instantiation of 'odb::oracle::object_statements': /usr/local/odb/include/odb/oracle/polymorphic-object-statements.hxx:35:5: instantiated from 'odb::oracle::polymorphic_root_object_statements' /usr/local/odb/include/odb/oracle/polymorphic-object-statements.hxx:176:56: instantiated from 'odb::oracle::polymorphic_derived_object_statements' employee-odb.cxx:147:21: instantiated from here /usr/local/odb/include/odb/oracle/simple-object-statements.hxx:396:38: error: 'odb::oracle::object_statements::container_statement_cache_' has incomplete type person-odb.hxx:263:12: error: forward declaration of 'struct odb::oracle::object_statements::container_statement_cache_type' In file included from /usr/local/odb/include/odb/oracle/simple-object-statements.hxx:492:0, from /usr/local/odb/include/odb/oracle/polymorphic-object-statements.hxx:23, from employee-odb.cxx:27: /usr/local/odb/include/odb/oracle/simple-object-statements.txx: In constructor 'odb::oracle::object_statements::object_statements(odb::oracle::statements_base::connection_type&) [with T = person, odb::oracle::statements_base::connection_type = odb::oracle::connection]': /usr/local/odb/include/odb/oracle/polymorphic-object-statements.txx:36:59: instantiated from 'odb::oracle::polymorphic_root_object_statements::polymorphic_root_object_statements(odb::oracle::polymorphic_root_object_statements::connection_type&) [with T = person, odb::oracle::polymorphic_root_object_statements::connection_type = odb::oracle::connection]' /usr/local/odb/include/odb/oracle/statement-cache.txx:21:54: instantiated from 'typename odb::object_traits::statements_type& odb::oracle::statement_cache::find_object() [with T = person, typename odb::object_traits::statements_type = odb::oracle::polymorphic_root_object_statements]' /usr/local/odb/include/odb/oracle/polymorphic-object-statements.txx:69:71: instantiated from 'odb::oracle::polymorphic_derived_object_statements::polymorphic_derived_object_statements(odb::oracle::statements_base::connection_type&) [with T = employee, odb::oracle::statements_base::connection_type = odb::oracle::connection]' /usr/local/odb/include/odb/oracle/statement-cache.txx:21:54: instantiated from 'typename odb::object_traits::statements_type& odb::oracle::statement_cache::find_object() [with T = employee, typename odb::object_traits::statements_type = odb::oracle::polymorphic_derived_object_statements]' employee-odb.cxx:232:57: instantiated from here /usr/local/odb/include/odb/oracle/simple-object-statements.txx:53:56: error: using invalid field 'odb::oracle::object_statements::container_statement_cache_' make: *** [employee-odb.o] Error 1 It appears that the person template code is in a file that is separate from the employee template code and that the employee templates can't access the person templates. Is there a way around this other than including all class definitions in one file? Any assistance would be appreciated. Below are additional environment details. Thank you in advance! Craig Environment: Solaris 10 gcc 4.5.2 Environment Variables: export CPPFLAGS='-I/usr/local/odb/include -I/usr/local/mysql/include -I/usr/local/sqlite/include -I/usr/local/oracle/instantclient_11_2/sdk/in clude -I/usr/local/boost/boost_1_49_0' export LDFLAGS='-L/usr/local/odb/lib -L/usr/local/mysql/lib -L/usr/local/oracle/instantclient_11_2 -L/usr/local/boost/boost_1_49_0/stage/lib' export PATH=/usr/local/dist/gcc-4.5.2/bin:/opt/SUNWspro/bin:/usr/local/odb/bin:/usr/local/oracle/instantclient_11_2:/usr/dt/bin:/usr/sbin:/usr /local/bin:/usr/bin:/usr/ucb:/etc:/usr/openwin/bin:/usr/ccs/bin:/usr/local/j2sdk1.4.2/bin:/usr/local/ssl-lnp/bin:. export LD_LIBRARY_PATH=/usr/local/dist/gcc-4.5.2/lib/gcc/sparc-sun-solaris2.10:/usr/local/dist/gcc-4.5.2/lib:/usr/local/oracle/instantclient_1 1_2:/usr/local/boost/boost_1_49_0/stage/lib:/usr/local/odb/lib:/usr/local/lib:/usr/openwin/lib:/usr/lib:/usr/dt/lib:/usr/dt/lib This e-mail message is for the sole use of the intended recipient(s)and may contain confidential and privileged information of Transaction Network Services. Any unauthorised review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. From boris at codesynthesis.com Thu May 31 09:19:21 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu May 31 09:19:28 2012 Subject: [odb-users] modified polymorphism example trouble... In-Reply-To: References: Message-ID: Hi Craig, Burton, Craig writes: > However, when I attempt to break the employee files into person.hxx, > person.cxx, employee.hxx and employee.cxx, I see the same behavior > as in my separate, static prototype. > > [...] > > /usr/local/odb/include/odb/oracle/simple-object-statements.hxx:396:38: > error: 'odb::oracle::object_statements::container_statement_cache_' > has incomplete type This is a bug in ODB. The container_statement_cache class is only defined in the generated source file corresponding to an object class. While this wasn't a problem before, now, with polymorphism support, we need to reference object statements from different classes in a hierarchy. And then this becomes a problem. Thanks for reporting it! I came up with a fix and prepared a test package for libodb-oracle: http://codesynthesis.com/~boris/tmp/odb/libodb-oracle-2.0.1.tar.gz I tested it with the modified polymorphism example as you described and it works as expected. I am pretty sure it will work for your application as well. Can you confirm this and then I will release the official bug-fix. Boris From Davide.Anastasia at qualitycapital.com Thu May 31 10:25:17 2012 From: Davide.Anastasia at qualitycapital.com (Davide Anastasia) Date: Thu May 31 10:26:22 2012 Subject: [odb-users] Creation of ODB cache In-Reply-To: References: Message-ID: Hi Boris, I'm back! :) Suppose I try to read from the database an object using load(KEY) and the KEY does not exist, I get an exception of type object_not_persistent. That's fair. However, I would love to have a different exception for each persistent type: is it that possible somehow? It would be great to be able to do something like: Try { Shared_ptr myObj1 = db.load(keyObj1); Shared_ptr myObj2 = db.load(keyObj2); } Catch (const obj1_not_persistent& ex) { ... } Catch (const obj2_not_persistent& ex) { ... } Is it that possible? Or should I try { } catch () {} for each db.load()? Thanks, Davide -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: 30 May 2012 15:01 To: Davide Anastasia Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] Creation of ODB cache Hi Davide, Davide Anastasia writes: > 1. can a session object be a member of a class? The session that is currently provided by ODB is per-thread (a pointer to the current session is stored in the TLS). It is also not thread- aware in the sense that a single session cannot be used safely from multiple threads concurrently. However, one can imagine that a shared, thread-aware implementation could be useful for some applications so we could add something like this in the future. So, to answer your question, yes, you can make a session object a member of a class though it will "attach" itself to the thread where the class' constructor is executed, which may or may not be what you want (you can "detach" it from the current and attach it to another thread using the provided "current" API). > I'm saying that because my class essentially runs into an std::thread > and waits for "updates" to store, starting a transaction every time: > > void run() > { > while (1) > { > // wait > Transaction t( ...) ; > > // load, persist, ? > > t.commit(); > } > } In this case it seems more straightforward to just do: void run() { session s; while (1) { .. } } Unless you plan to restart the thread and want to keep the session's contents. > 2. how many session object can my application have? Can it make sense > to have a session at the beginning of the application as "master" session? I think the above explanation should make this clear now. Currently, you can have one active session per thread. > 3. If I do a conditional search, is the retrieved object stored in the > session? You mean if you execute a query? In that case, yes, if you actual instantiate the object (i.e., dereference the iterator), then yes, the object will be cached. > 4. Does session apply to Views? No, views are not stored in a session (they have no object ids). > To many questions, I know :) No problem. It is always good to understand how people are using (or trying to use) ODB. Boris From boris at codesynthesis.com Thu May 31 12:24:16 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu May 31 12:24:25 2012 Subject: [odb-users] Creation of ODB cache In-Reply-To: References: Message-ID: Hi Davide, Davide Anastasia writes: > Suppose I try to read from the database an object using load(KEY) > and the KEY does not exist, I get an exception of type > object_not_persistent. That's fair. However, I would love to have a > different exception for each persistent type: is it that possible > somehow? No, not at the moment. We were thinking about adding some kind of type information (and maybe object id) in some way, but there doesn't seem to be good way to do this in a type-independent way. I guess throwing a type-specific exception would be one way to do it. The problem, of course, is the potential code bloat that it would lead to. Another option would to add an std::type_info reference that would identify the class. > It would be great to be able to do something like: > > Try > { > Shared_ptr myObj1 = db.load(keyObj1); > Shared_ptr myObj2 = db.load(keyObj2); > } > Catch (const obj1_not_persistent& ex) > { > ... > } > Catch (const obj2_not_persistent& ex) > { > ... > } What would you do in the catch() {} blocks? In other words, what type-dependant actions are you planning to do? Boris From Davide.Anastasia at qualitycapital.com Thu May 31 12:42:22 2012 From: Davide.Anastasia at qualitycapital.com (Davide Anastasia) Date: Thu May 31 12:42:28 2012 Subject: [odb-users] Creation of ODB cache In-Reply-To: References: Message-ID: Hi Boris, Could you derive the exceptions for each class as derivation of object_not_persistent? In this way, you can either give the possibility to catch a class-dependent exception, or a more general one. I am currently using ODB in the server-side of a more complex application, based on messaging between GUI and backend. However, in some cases, the user might put some wrong data in some field: I would love to avoid, but unfortunately I can't (it's a long reason why!). So my current aim is to provide a sensible error message in the response message, so the user can quickly spot the error and fix that. Feel free to ask more, if needed. Best, Davide -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: 31 May 2012 17:24 To: Davide Anastasia Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] Creation of ODB cache Hi Davide, Davide Anastasia writes: > Suppose I try to read from the database an object using load(KEY) > and the KEY does not exist, I get an exception of type > object_not_persistent. That's fair. However, I would love to have a > different exception for each persistent type: is it that possible > somehow? No, not at the moment. We were thinking about adding some kind of type information (and maybe object id) in some way, but there doesn't seem to be good way to do this in a type-independent way. I guess throwing a type-specific exception would be one way to do it. The problem, of course, is the potential code bloat that it would lead to. Another option would to add an std::type_info reference that would identify the class. > It would be great to be able to do something like: > > Try > { > Shared_ptr myObj1 = db.load(keyObj1); > Shared_ptr myObj2 = db.load(keyObj2); } Catch (const > obj1_not_persistent& ex) { > ... > } > Catch (const obj2_not_persistent& ex) > { > ... > } What would you do in the catch() {} blocks? In other words, what type-dependant actions are you planning to do? Boris From crburton at tnsi.com Thu May 31 13:21:45 2012 From: crburton at tnsi.com (Burton, Craig) Date: Thu May 31 13:22:16 2012 Subject: [odb-users] modified polymorphism example trouble... In-Reply-To: References: Message-ID: Hi Boris, Thank you for your very rapid response and solution -- your fix works perfectly! Craig -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Thursday, May 31, 2012 6:19 AM To: Burton, Craig Cc: odb-users@codesynthesis.com Subject: Re: [odb-users] modified polymorphism example trouble... Hi Craig, Burton, Craig writes: > However, when I attempt to break the employee files into person.hxx, > person.cxx, employee.hxx and employee.cxx, I see the same behavior > as in my separate, static prototype. > > [...] > > /usr/local/odb/include/odb/oracle/simple-object-statements.hxx:396:38: > error: 'odb::oracle::object_statements::container_statement_cache_' > has incomplete type This is a bug in ODB. The container_statement_cache class is only defined in the generated source file corresponding to an object class. While this wasn't a problem before, now, with polymorphism support, we need to reference object statements from different classes in a hierarchy. And then this becomes a problem. Thanks for reporting it! I came up with a fix and prepared a test package for libodb-oracle: http://codesynthesis.com/~boris/tmp/odb/libodb-oracle-2.0.1.tar.gz I tested it with the modified polymorphism example as you described and it works as expected. I am pretty sure it will work for your application as well. Can you confirm this and then I will release the official bug-fix. Boris This e-mail message is for the sole use of the intended recipient(s)and may contain confidential and privileged information of Transaction Network Services. Any unauthorised review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. From boris at codesynthesis.com Thu May 31 14:54:39 2012 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu May 31 14:54:45 2012 Subject: [odb-users] Creation of ODB cache In-Reply-To: References: Message-ID: Hi Davide, Davide Anastasia writes: > Could you derive the exceptions for each class as derivation of > object_not_persistent? > In this way, you can either give the possibility to catch a > class-dependent exception, or a more general one. Yes, we could certainly do that. The problem, as I mentioned earlier, is code bloat. With each per-object exception comes a virtual function table, type information, destructor, what(), etc, etc. Seeing that this functionality is probably not needed by every applications (you are the first person asking for something like this), I am not sure this is a good idea. That's also the reason why I was thinking about std::type_info -- it is a much lighter-weight approach, if quite a bit less convenient to use. > So my current aim is to provide a sensible error message in the > response message, so the user can quickly spot the error and fix > that. With the type_info approach you will easily be able to find which object triggered the exception with code along these lines: try { ... } catch (const std::object_not_persistent& e) { std::type_info& ti (e.class_info ()); if (ti == typeid (object1)) { } else if (ti == typeid (object2)) { } } It is not as elegant as having a separate exception, but is semantically equivalent. What other information will you want to include in your error message. For example, will you need to know the id of the object in question? Boris