cpdo

cpdopp
Login

cpdopp

ACHTUNG: THE CPDO WIKI IS NOW (AS OF 2011-May-17) MAINTAINED ON A DEDICATED WIKI SITE: http://whiki.wanderinghorse.net/wikis/cpdo/?page=cpdopp

As of 20110210, cpdo includes a C++ wrapper API. It is really easy to use...

#include "wh/cpdo/cpdo.hpp"
...

cpdo::driver * drv = new cpdo::driver("sqlite3:/path/to/db.sqlite3");
...
cpdo::stmt st( drv->prepare("SELECT * FROM t") );
// Note that cpdo::stmt is a std::auto_ptr-like convenience class
// for managing cpdo::statement pointer lifetime, and thus we
// use the '->' operator even though 'st' isn't a pointer...
while( st->step() ) {
   std::cout << st->get_int32(0) << '\n';
}
st.finalize(); // might not be necessary: see the API docs.
               // We use it here because the statement must be
               // finalized before we do this:
delete drv;

The main usage difference between the C and C++ APIs is that the C++ wrapper throws exceptions (cpdo::exception, which derives from std::exception) for the vast majority of error cases. See the API docs for the details and the small handful of functions which do not throw.