Skip to content

mattvchandler/sqlitepp

Repository files navigation

Sqlitepp - a thin C++ wrapper library for Sqlite

Sqlitepp is a simple wrapper for sqlite. It simply adds RAII to the most commonly used sqlite types and a few convenience methods for their most used functionality. Sqlitepp types have a get_c_obj() method to gain access to the underlying sqlite type, which allows you to use any part of the sqlite C library not wrapped by sqlitepp. That way you can take advantage of sqlitepp without losing any functionality.

Structure

The library is split into 4 modules:

sqlite::Connection (corresponds to sqlite's sqlite3 type)

Represents the sqlite database connection itself.

sqlite::Connection::Stmt (corresponds to sqlite's sqlite3_stmt type)

A prepared SQL statement. Can be created directly, or from sqlite::Connection::create_statement

sqlite::Error, sqlite::Runtime_error, sqlite::Logic_error

Exception types thrown from Connection and Stmt. sqlite::Error is an abstract type, and should not be directly created, but may be caught. sqlite::Runtime_error and sqlite::Logic_error inherit from c++'s std::runtime_error and std::logic_error, respectively.

sqlite::Database

A simple service locator object for use with Connection. This is provided as a convinence, and is not required to use the rest of the library.

Building & Installation

Dependencies

  • Sqlite

Sqlitepp uses CMake to build:

$ mkdir build && cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=<prefix path> # add -DBUILD_SHARED_LIBS for a shared libary
$ make
# make install

Debian & derivatives

Sqlitepp is configured to generate a .deb package file. To do so, substitute the above with the following:

$ mkdir build && cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=1
$ make
$ cpack
# dpkg -i libsqlitepp-dev*.deb

When linking your own code using sqlitepp, you will need to link to both the sqlitepp and sqlite3 libraries: -lsqlitepp -lsqlite3 (depending on your OS)

Documentation

If doxygen is installed, library documentation can be generated with: $ make doc