Boost logo

Boost :

Subject: Re: [boost] SQL client library ?
From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2009-09-06 13:18:02

> Jean-Louis Leroy wrore
> What's the situation with SQL client libraries (similar to Rogue Wave's
> DBTools.h++) ? I know that there's a boost_sql_cli in the Vault, but it
> doesn't seem to make much progress. I have also heard about plans to
> bring Soci into Boost.

I toiled with some ideas a while ago around this. My goal was to be able to
write something like this:

using namespace database;
field::integer age;
field::date dob;
field::string name;
table employee;

connection db("connect_string","user","passwd");
recordset rs(db);
rs = SELECT name,age,dob FROM employee WHERE age>45;
while (rs.fetch())
    std::cout << name << "\t" << age << "\t" << dob << "\n";

In the absence of whitespace overloading, the only way to achieve this
syntax is to use the preprocessor to define SELECT, FROM and WHERE to be
something than can invoke a binary operator. This is less than ideal as the
C++ preprocessor is global, so you can't restrict SELECT definition to be in
the database namespace. It is impossible to support SQL aliases or tablename
prefixes with this syntax, though.

With the small problem of macros - which I see no way to oversome - and is
actually quite a big problem, I did achieve some success using template
expressions to build a query and generate SQL that is executed and bound to
a recordset.

-- Craig

Boost list run by bdawes at, gregod at, cpdaniel at, john at