|
Boost : |
Subject: [boost] Boost.SQL?
From: Roland Bock (rbock_at_[hidden])
Date: 2010-09-14 09:26:55
Hi,
currently I am working on a set of header files which are supposed to
make the life of C++ developers easier when in comes to interacting with
databases (based on SQL). Goals are:
* Stay close to SQL syntax
* Do as much type checking as possible
* prevent oversights and typical security holes, e.g. by forgetting to
escape strings
The basic idea is, that given a table definition, it should be possible to
* offer a lot of checks at compile time for building a query
* make it hard to misinterpret the results
Until now, I have been concentrating on table definitions and select
statements.
Here's a very simplistic example, assuming a table definition "my_table"
and a database connection "db":
// -------------------------------------------------------------------------
using boost;
typedef my_table<> t;
typedef sql::select_record<t> record;
std::string name("Peter");
...
std::vector<record> records =
db.select<record>(
sql::where(t::id() > 1000 && t::first_name() == name),
sql::order_by(t::priority()(sql::desc)),
sql::limit(17));
// the values can be accessed by their name
// and are of the correct type, e.g.
records.front().first_name_; // is a string
records.front().middle_name_; // optional<string> because the table
definition says that it can be NULL
// In case of a select from more than one table, the values can also be
accessed like this
records.front().my_table_.first_name;
// -------------------------------------------------------------------------
I wonder if there would be interest for such a library in boost.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk