Boost logo

Boost :

Subject: Re: [boost] SQL client library ?
From: Jean-Louis Leroy (jl_at_[hidden])
Date: 2009-09-07 05:48:06


joel wrote:
> Back at Boost'Con 09 I proposed a function based and not text based
> SQL interface using proto that looked like :

Here's my idea after some experimenting :

namespace tables {
    BOOST_RDB_BEGIN_TABLE(person)
    BOOST_RDB_COLUMN(int, id)
    BOOST_RDB_COLUMN(int, name)
    BOOST_RDB_END_TABLE()

    BOOST_RDB_BEGIN_TABLE(link)
    BOOST_RDB_COLUMN(int, husband)
    BOOST_RDB_COLUMN(int, wife)
    BOOST-RDB_END_TABLE()
}

// aliases
tables::person husband("h"), wife("w");

// SELECT h.id, w.id, h.name FROM person h, person w, link
// WHERE h.id = link.husband AND link.wife = wife.id

auto query = select(husband.id, wife.id, husband.name).from(husband,
wife, link::_)
  .where(husband.id == link::_.husband && link::_.wife == wife.id);

// less sure about the rest...

auto statement = db.prepare(query);

auto cursor = statement.execute();
cursor.fetch();
cout << cursor[0] << endl; // positional : husband.id
cout << cursor[husband.id] << endl;
cout << cursor[husband.name] << endl; // error : not in selected columns
int id = cursor[2] << endl; // error : it's a string

// SELECT * FROM person WHERE name = ?

auto query = select(person::_).from(person::_)
  .where(person::_.name == _);

auto statement = db.prepare(query);
statement.values("Simpson");

auto cursor = statement.execute();
// etc
>
> I have the whole ppt of my proposal somewhere if soemone's interested.
I am.
> I have alas not much free time for this but I had some prototype code
> laying somewhere
Me neither ;-)

J-L


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk