What is a good OO C++ wrapper for sqlite [closed]

This is really inviting down-votes, but here goes...

I use sqlite directly from C++, and don't see any value with an added C++ abstraction layer. It's quite good (and efficient) as is.


Another good wraper for databases in C++ is SOCI. It's not very OO, but the more Modern C++.

It supports Oracle, PostgreSQL and MySQL. A SQLite backend is in the CVS.


I read this post and tried some of the libraries mentioned in the answers ,
But none of them was easy enough for me ( i am a lazy programmer ! ).

So i wrote my own wrapper : sqlite modern cpp

database db("dbfile.db");
// executes the query and creates a 'user' table if not exists
db << "create table if not exists user ("
      "   age int,"
      "   name text,"
      "   weight real"
      ");";
// inserts a new user and binds the values to '?' marks
db << "insert into user (age,name,weight) values (?,?,?);"
        << 20
        << "bob"
        << 83.0;
// slects from table user on a condition ( age > 18 ) and executes 
// the lambda for every row returned .
db << "select age,name,weight from user where age > ? ;"
   << 18
   >> [&](int age, string name, double weight) {
       cout << age << ' ' << name << ' ' << weight << endl;
   };
// selects the count(*) of table user
int count = 0;
db << "select count(*) from user" >> count;

Have fun !


Here's one that hasn't been updated in a while, but compiles and runs on Mac OS GCC 4.3. It's also released under the MIT License, so you can use it in a commercial project, no problems. http://code.google.com/p/sqlite3pp/

The usage is boost-ified and very clean:

sqlite3pp::database db("test.db");
sqlite3pp::transaction xct(db);
{
    sqlite3pp::command cmd(db, "INSERT INTO contacts (name, phone) VALUES (:user, :phone)");
    cmd.bind(":user", "Mike");
    cmd.bind(":phone", "555-1234");
    cmd.execute();
}
xct.rollback();

See: http://code.google.com/p/sqlite3pp/wiki/UsagePage


Use Qt - it has great binding for SQLite that fits well into its overall design