1

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.

Jiminion
  • 5,080
  • 1
  • 31
  • 54
mike
  • 23
  • 2
  • The example [here](http://www.codesynthesis.com/products/odb/doc/manual.xhtml#2.9) seems to be what you need. In the example they use the command line, but you may parse your own config file and then create the appropriate database pointer. – Nemikolh Oct 28 '13 at 08:29
  • @Nemikolh, I have managed to compile the person.hxx (with -m dynami -d common) but could not manage to make the driver. The one provided [here](http://www.codesynthesis.com/products/odb/doc/manual.xhtml#16.2) is incomplete. If you have a some sample code working. please share. I'm still trying to work this out. – mike Oct 30 '13 at 11:42

1 Answers1

1

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.

Nemikolh
  • 700
  • 4
  • 19
  • I managed to make my app connect to multiple databases just as I wanted, took quite a number of attempts but I managed it. For some reason, I wasn't able to respond in good time. Thank you for helping out. – mike Nov 07 '13 at 16:06
  • Side note: one has to include the generated person-odb-mysql.cxx and person-odb-sqlite.cxx files during the linking, not only the person-odb.cxx, otherwise you'd get a coredump. And if you put those generated files into a library, you need to use the -Wl,--whole-archive flag to include all symbols, otherwise you'd get also a coredump.. – jav Nov 15 '17 at 13:45