[odb-announcements] ODB 2.2.0.a1 available

Boris Kolpackov boris at codesynthesis.com
Mon Oct 29 11:04:18 EDT 2012


Hi,

The first alpha version for the upcoming ODB 2.2.0 is now available. The
NEWS file entries so far are:

 * Static multi-database support. It allows an application to simultaneously
   work with multiple database systems using their static interfaces (i.e.,
   odb::<database>::database instead of odb::database).

 * Support for prepared queries. Prepared queries are a thin wrapper around
   the underlying database system's prepared statements functionality. They
   provide a way to perform potentially expensive query preparations tasks
   only once and then executing the query multiple time. For more information,
   refer to Section 4.5, "Prepared Queries" in the ODB manual as well as the
   'prepared' example in the odb-examples package.

 * Support for early connection release. Now the database connection is
   released when commit()/rollback() is called rather than when the
   transaction instance goes out of scope.

We are still working on the dynamic multi-database support as well as the
documentation for both static and dynamic. Below is a quick guide to using
the static support.

==========================================================================

As an example, let's say we want to use both PostgreSQL and SQLite in our
application. To access these two databases with ODB we will need to
generate (a) common database support code, (b) PostgreSQL support code,
and (c) SQLite support code:

odb -m static -d common -q person.hxx
odb -m static -d pgsql -q -s person.hxx
odb -m static -d sqlite -q -s person.hxx

Note the -m (short for --multi-database) option which enables the multi-
database support. We could have also used a single invocation of the ODB
compiler:

odb -m static -d common -d pgsql -d sqlite -q -s person.hxx

The above commands (either version) will produce the following set of
files:

person-odb.?xx          - common code
person-odb-pgsql.?xx    - Postgres-specific code
person-odb-sqlite.?xx   - SQLite-specific code

person-pgsql.sql        - database schema for Postgres (for SQLite by default
                          the schema is embedded in person-odb-sqlite.cxx)

In our own code, compared to single-database support, we will need to
do the following two things differently:

1. We will need to include person-odb-{pgsql,sqlite}.hxx instead of
   person-odb.hxx.

2. We will need to use the static, database-specific interface instead
   of the common, database-independent one. For example, we will need
   to use odb::pgsql::database instead of odb::database, etc., when
   working with objects stored in Postgres.

Here is an example:

#include <odb/pgsql/database.hxx>
#include <odb/pgsql/transaction.hxx>

#include <odb/sqlite/database.hxx>
#include <odb/sqlite/transaction.hxx>

#include "person.hxx"
#include "person-odb-pgsql.hxx"
#include "person-odb-sqlite.hxx"

namespace pg = odb::pgsql;
namespace sl = odb::sqlite;

int
main ()
{
  pg::database pdb ("boris", "secret", "test_db");
  sl::database sdb ("test.db");

  person p1 (...);
  person p2 (...);

  // Postgres transaction.
  //
  {
    pg::transaction t (pdb.begin ());
    pdb.persist (p1);
    t.commit ();
  }

  // SQLite transaction.
  //
  {
    sl::transaction t (sdb.begin ());
    sdb.persist (p2);
    t.commit ();
  }

  // Postgres query transaction.
  //
  {
    typedef pg::query<person> query;
    typedef odb::result<person> result; // Note: odb:: , not pg:: .

    pg::transaction t (pdb.begin ());
    result r (pdb.query<person> (query::age < 30));
    t.commit ();
  }
}

Note that odb::result is always database-independent (i.e., there is
no odb::pgsql::result class template).

It is also possible to make one of the databases the default database
so that it can be accessed via the common interface, just like with
the single-database support. For that we use the --default-database
option:

odb -m static -d common -d pgsql -d sqlite --default-database pgsql \
-q -s person.hxx

With multi-database support it is now possible to restrict ODB pragmas
to apply only to specific databases. For example:

#pragma db object
class person
{
  ...

  #pragma db pgsql:type("VARCHAR(128)") sqlite:type("TEXT")
  std::string name_;

  unsigned short age_;

  #pragma db pgsql index member(age_)
};

The first example shows a database prefix (e.g., pgsql:) that only
applies to the following specifier. The second example shows the
database prefix that applies to the whole pragma. In this case the
database name must immediately follow the 'db' keyword.

Similar to pragmas, ODB compiler options that determine the kind of
output (e.g., --schema-format) or alter the output itself (e.g.,
prologue and epilogue options) can now be prefixed with the database
name. For example:

--odb-file-suffix common:-odb-common

==========================================================================

This pre-release is available from:

http://www.codesynthesis.com/download/odb/pre-release/

The SHA1 sums for all the files in this pre-release are provided at the
end of the email.

Testing and feedback are much appreciated.

Enjoy,
	Boris


3247f50afef3bff8cf33765ef0157246d9ffaef8  libodb-2.2.0.a1.tar.bz2
7b4e80987dff77e6fa9ad58ecaf86b09bfd15389  libodb-2.2.0.a1.tar.gz
1ace5fddcac763e3bba532486e1ac0be24f82d48  libodb-2.2.0.a1.zip
61ca1acb08b3d857323217c38d1d459de9001e28  libodb-mssql-2.2.0.a1.tar.bz2
b44caa46f50a998235cb100e8413edfddabad80d  libodb-mssql-2.2.0.a1.tar.gz
d481a26fe34e7db9aa34b5a0f26e07d72cb20c7d  libodb-mssql-2.2.0.a1.zip
fcd6e2a956d02c4b0ae499b12937e1d79f9d8dd7  libodb-mysql-2.2.0.a1.tar.bz2
3007aec103e3f02d4269e6772a1038ab78c7be87  libodb-mysql-2.2.0.a1.tar.gz
a8d3768435d3939bf6c4ce49cdd9ac72ec9eb39c  libodb-mysql-2.2.0.a1.zip
4aa77014ebe31af946d52ff137cce6af128fc2d9  libodb-oracle-2.2.0.a1.tar.bz2
75ea118e5c26098330d43d30034fe1a203f940bd  libodb-oracle-2.2.0.a1.tar.gz
843068a5310bd330a753159959e4fedf054f3737  libodb-oracle-2.2.0.a1.zip
f65ac2602597d2eaafd618d2132e277afa4c0322  libodb-pgsql-2.2.0.a1.tar.bz2
d23dec3420104c8a4ae8466b731dd5bd9f216360  libodb-pgsql-2.2.0.a1.tar.gz
78d186ea49321b877a3e136a07c97abff450375b  libodb-pgsql-2.2.0.a1.zip
eee8de6b3a689eacaa851755aea83ec29f3fa12e  libodb-qt-2.2.0.a1.tar.bz2
ee69ef8c777732656958457032aaa7d5dec5a05c  libodb-qt-2.2.0.a1.tar.gz
e0e16e6e973f1943ea638d3d8982d98370dfe6ef  libodb-qt-2.2.0.a1.zip
8f7982cd14d0aaf69a328e664e6207bfc7c2a2bd  libodb-sqlite-2.2.0.a1.tar.bz2
ebe704c17e2182bd41352206e61d078e935bf7bb  libodb-sqlite-2.2.0.a1.tar.gz
b273ad1be20c7ff8a450a216a89b893ae78f2a62  libodb-sqlite-2.2.0.a1.zip
d966000b22ffddaa6c40d98ca2cf583f16bf4180  odb-2.2.0.a1-i686-linux-gnu.tar.bz2
8012cd0e1ce2b27e5cd108a938cf66fb2a58372c  odb-2.2.0.a1-i686-windows.zip
4b3ac77b4d9fa0957daaa12728d5a1a143dbbd9f  odb-2.2.0.a1.tar.bz2
48014dc5f12758754b5b7342e039e713f771572f  odb-2.2.0.a1.tar.gz
f4a382462429e9bb18d7f15790b15c75a664b4d4  odb-2.2.0.a1-x86_64-linux-gnu.tar.bz2
7209a4cf9d3c140db0e695b8261f55954d75d41f  odb-2.2.0.a1.zip
a951d68dcc9971e56e077740f843c1d1d9b8cdfa  odb-examples-2.2.0.a1.tar.bz2
992d309fe5445eb06ebaf4b7e10b4bbccbad800c  odb-examples-2.2.0.a1.tar.gz
613ba4dd1219ebcd91d84da057fe4faf7426be7f  odb-examples-2.2.0.a1.zip
c155e5f4b5b6ffc3715415196e22f490bc9e39aa  odb-tests-2.2.0.a1.tar.bz2
823595b17729ba199953075af0467a7617a14c97  odb-tests-2.2.0.a1.tar.gz
7cd02c40ef08ee3bdc250552688c0276ab8bc260  odb-tests-2.2.0.a1.zip



More information about the odb-announcements mailing list