[odb-users] Include of SQLite files and ODB compiler

Erez Pics picserez at gmail.com
Tue Nov 25 04:58:21 EST 2014


Hi Boris,

I am so impressed, prompt, accurate and full solution every time,
Boris's magic at work :-)

Indeed it solved, currently I am simply using ifndef which works like a charm :

#ifndef ODB_COMPILER
#include <odb/sqlite/database.hxx>
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/transaction.hxx>
#else
#include <odb/sqlite/forward.hxx>
#endif // ODB_COMPILER

This raises an interesting question, I am using SQLite database and
link to the ODB SQLite lib,
however I can use regular ODB objects in most cases that do not
require specific SQLite functionality,
most general ODB objects have a similar interface to their SQLite
counterparts and seem to work the same.

Does switching to use explicit ODB::SQLite objects translates to any
performance or other advantage VS general ODB objects ?
[for example odb::query to odb::sqlite::query and so forth]

Thank you very much,
Erez.

On Tue, Nov 25, 2014 at 9:06 AM, Boris Kolpackov
<boris at codesynthesis.com> wrote:
> Hi Erez,
>
> Erez Pics <picserez at gmail.com> writes:
>
>> [Switched to plain text client, hope it helps]
>
> Yes, much, much, better. Thank you.
>
>
>> I used ifndef to make the ODB compiler ignore these includes:
>> #ifndef ODB_COMPILER
>> #include <odb/sqlite/database.hxx>
>> #include <odb/sqlite/connection.hxx>
>> #include <odb/sqlite/transaction.hxx>
>> #endif // ODB_COMPILER
>>
>> Which indeed fixed the error and cause another one, because we are
>> passing odb::sqlite::database object in our code, it does not know the
>> sqlite namespace:
>>  error: 'sqlite' is not a member of 'odb'
>>
>> How would you recommend to resolve this problem ?
>
> While you cannot include most libodb-sqlite headers into headers that
> you compile with the ODB compiler, there is an exception: forward.hxx
> which forward-declares odb::sqlite::database besides other things. So
> the way I would suggest you structure your header/source is as follows:
>
> // header
> //
> #include <odb/sqlite/forward.hxx>
>
> class object
> {
>   ...
>
>   void do_it (odb::sqlite::database&);
> };
>
> // source
> //
> #include <odb/sqlite/database.hxx>
>
> void object::do_it (odb::sqlite::database& db)
> {
>   db.persist (*this);
> }
>
> The idea here is to only use/pass references/pointers to database in
> the header for which a forward-declaration is sufficient. In the source
> file, howevere, you include <odb/sqlite/database.hxx> and can call
> database operations, etc.
>
> Boris



More information about the odb-users mailing list