Skip to content


Subversion checkout URL

You can clone with
Download ZIP
C++ database API
C++ Shell C Other
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bench sqlite3: fix Handle::write() bug that skipped last column value. clea…
debian updated changelog
demo example cleanup
doc docs
lib cmakeified
memory memory check for Handle::write
modules update search path for mysql headers.
src add Statement & Query operators for binding dbi::Param
.gitignore ignore deb build files
AUTHORS initial debian package meta
BUGS add link to issues & update todo
CHANGELOG better getline() detection on macosx
CMakeLists.txt install pkgconfig files under lib prefix
HACKING add link to issues & update todo
NEWS swift does not use dbic++ anymore
TODO initial debian package meta
build better getline() detection on macosx
configure configure wrapper changes

C++ database interface

dbic++ is a database client library written in C++ which comes with support for the following databases,

  • PostgreSQL >= 8.3
  • MySQL >= 5.0
  • SQLite >= 3.7


  • Simple and fast.
  • Support for PostgreSQL, MySQL and SQLite3.
  • Nested transactions.
  • API for async queries (PostgreSQL and MySQL).



  #include "dbic++.h"
  #include <unistd.h>

  using namespace std;
  using namespace dbi;

  int main() {

      // Handle h ("driver", "user", "password", "database", "host", "port");
      Handle h ("postgresql", dbi::getlogin(), "", "dbicpp");

      Query query (h, "SELECT id, name, email FROM users WHERE id >= ? AND id < ?");

      // bind and execute the statement.
      query % 1L, 10L;

      ResultRow r;
      while (
          cout << r.join("\t") << endl;

      // or you can do
      ResultRowHash rh;
      while (
          cout << rh["id"]    << "\t"
               << rh["name"]  << "\t"
               << rh["email"] << endl;


See src/examples for more specific examples.



If you are building from source you need to install a few dependencies before you compile dbic++. To begin with you need a working build environment with a c++ compiler (XCode if you are a MacOSX user).

Most flavors of unix.

  • cmake
  • pcre3 development libraries
  • uuid development libraries
  • mysql client libraries (optional)
  • postgresql client libraries (optional)
  • sqlite3 development libraries (optional)


  sudo apt-get install build-essential
  sudo apt-get install cmake libpcre3-dev uuid-dev
  sudo apt-get install libmysqlclient-dev libpq-dev libsqlite3-dev


I'm assuming you're using homebrew. If not, please go to

brew install directly the latest version

brew install


brew install

or you can pick and choose the database bindings you want to compile.

  brew install cmake
  brew install pcre
  brew install ossp-uuid
  brew install sqlite3
  brew install postgresql
  brew install mysql

You need atleast one of the database client libraries. Just unpack dbic++ and do ./build -i

Building libraries and demos


System wide install of libraries

  sudo ./build -i

Cleanup and uninstall

  ./build -c
  sudo ./build -u

Building Debian packages

If you need to build debian packages yourself, you may need the following in addition.

  sudo apt-get install cdbs debhelper devscripts

To build debian packages for your local architecture,

  ./build -d

If you are too lazy to compile your own binaries you can use the ubuntu ppa at

  sudo add-apt-repository ppa:deepfryed/dbic++
  sudo apt-get update
  sudo apt-get install dbic++-dev dbic++-pg dbic++-sqlite3 dbic++-mysql

Running the demo

A few c++ examples can be found under src/examples/ and once you finish building the binaries can be found under demo/

  ./demo/demo  [mysql|postgresql|sqlite3]
  ./demo/async [mysql|postgresql]

Populating MySQL time zone tables.

This is not mandatory but would allow you to set timezones using Handle#setTimeZone method in dbic++.

On most unix systems it can be done as,

  mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

Refer to


You can run these yourself if you're keen. The makefile might need some tweaks on non-debian based distributions. The following results were obtained on a Core2DUO 2.53GHz, 4GB, 5200rpm drive with stock database configs.

  * The dataset size is 50 rows of 3 fields (id, text, timestamp)
  * 10000 SELECT queries run back to back, fetching all rows and printing them.

    cd bench/ && make


    + Setting up sample data (50 rows)
      * mysql
      * postgresql
    + Done

    ./ -w bench -n10000

    + Benchmarking mysql

      * mysql      user 0.69 sys 0.21 real 2.34
      * mysql++    user 1.06 sys 0.09 real 2.74
      * dbic++     user 0.81 sys 0.25 real 2.58

    + Benchmarking postgresql

      * pq         user 0.42 sys 0.14 real 2.01
      * dbic++     user 0.49 sys 0.12 real 2.05

    + Finished


  • sqlite3: Simulate async IO operations.
  • mysql: Proper bind parameter interpolation for Handle::execute(string, vector&)
  • Cursor support, generic interface to database specific api.


  • sqlite3: No support for async operations yet.
  • mysql: Handle::execute(...) replaces ? with given bind parameters if bind parameters are provided. Any literal values with ? character will be interpreted as a bind argument. If you are using Handle::execute(...) with bind arguments, make sure to provide all values as bind parameters to avoid the confusion and resulting errors.


Creative Commons Attribution - CC BY


Like any other OSS, do your research and do your testing (especially if you're using it in space shuttles).

Something went wrong with that request. Please try again.