Boost logo

Boost :

Subject: Re: [boost] sqlpp11: SQL for C++
From: Roland Bock (rbock_at_[hidden])
Date: 2013-11-09 17:58:49

On 2013-11-09 23:03, Michael Marcin wrote:
> On 11/9/2013 4:03 PM, Roland Bock wrote:
>> Please let me know your questions/thoughts/suggestions/rants.
>> Contributions welcome, of course :-)
> Could you compare your library with SOCI?
I consider SOCI to be a string and position based approach, meaning that
you (as a library user) have to use strings to construct your queries
and positions to extract results. Here is one of SOCI's introductory

// ------------------------
int id = 17;
string name;
int salary;
sql << "select name, salary from persons where id = " << id,
       into(name), into(salary);
// ------------------------

In sqlpp11 this would read something like this

// ---------------------
auto result =,
persons.salary).from(persons).where( == 17));
if (!result.empty())
   const auto row = result.front();
   std::string name =;
   int salary = row.salary;
// ---------------------

Notice that there are no strings being used in the sqlpp11 code at all.
The compiler can see and check the syntax of your query. If you mistype
anything, or if you compare apples and oranges (e.g. a text column and
an int), or if you forget the 'from' before the 'where' for instance, it
will let you know with compile errors.

Also, it is much harder to mix up stuff in the results. Imagine a
slightly larger list of columns being selected. With SOCI you need to
keep the "select a, b, c, d" in sync with the into(a), into(b), into(c),

sqlpp11 takes care of this responsibility for you and gives you rows
with appropriately named and typed member variables. It is much harder
to use those the wrong way without the compiler yelling at you.

sqlpp11 assumes that you know your tables at compile time. Thus you can
declare types representing tables and columns with appropriate names and
types. You can then construct SQL queries and analyze the results with
the full armory of syntax and type checking that C++ and template meta
programming have to offer.



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