C++ ODB Support Different DBMS

785 Views Asked by At

I have been looking at ODB ORM for some time now and had some practice with it. My problem is switching between different DBMS recompiling the code. From my Java background, I can simply change a config file and the ORM works e.g Hibernate. This far I can compile the 'hello' example under 'odb-examples-2.2.0.tar.gz' and connect to MySQL and PostgreSQL successfully.

Please share your ways of resolving this. Code samples would also be very helpful. I would like to simply change databases by say changing a config file. This far, referring to the manual has not helped yet. My system needs to be cross-platform.

Thanks.

1

There are 1 best solutions below

2
On BEST ANSWER

If dynamic support is sufficient for you, then the following example will do the trick. The following command line is needed before compiling the other files :

odb --std c++11 --multi-database dynamic -d common -d mysql -d sqlite \
--generate-query --generate-schema person.hxx

In my example I'm using the command line as they did in the manual (2.10). From what I've read, while you're using the odb::query, odb::transaction, you don't need to do anything else special to work with multiple databases.