cpdo  Artifact Content

Artifact 50cea121708f13d4cff0e3493ef404feb3338f5d:

Wiki page [cpdopp] by stephan 2011-05-17 18:39:29.
D 2011-05-17T18:39:29.668
L cpdopp
P 696186b5cf7fa6ed52f8b3f8e9663f5c5e8ad445
U stephan
W 1172
<strong>ACHTUNG: THE CPDO WIKI IS NOW (AS OF 2011-May-17) MAINTAINED ON A DEDICATED WIKI SITE:</strong> [http://whiki.wanderinghorse.net/wikis/cpdo/?page=cpdopp]

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

<verbatim>
#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;
</verbatim>

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

Z 47b4e8729fb18b91c1307a5fbb61dba6