sqlitepp
C++ binding for the SQLite3 library
|
sqlitepp is a C++ wrapper for the official SQLite3 C API.
sqlitepp uses GNU Make as a build tool. To build sqlitepp from source, download the source from git.ireas.org and then run make
. You might have to change the settings in config.mk
.
To connect to a SQLite database, you just have to create a new sqlitepp::Database object.
This snippet is equivalent to:
If the database file does not already exist, it is created. If an error occurs during the creation of the database, a sqlitepp::DatabaseError is thrown.
To execute a simple statement, use sqlitepp::Database::execute:
If you want to execute more complex statements, for example selection or insertion, use prepared statements. You can prepare a statement using sqlitepp::Database::prepare. You can then bind values (if necessary) using the bind
methods of sqlitepp::Statement and execute the statement using sqlitepp::Statement::execute. execute
returns a sqlitepp::ResultSet that stores the returned values (if any).
The recommended way to handle insertions are named bindings:
If an error occurs during an operation, an exception is thrown. All SQLite3 database errors are wrapped in sqlitepp::DatabaseError. If a method returns, it was successful (if not stated otherwise in the method documentation).
sqlitepp uses RAII. This means that the destructors of sqlitepp::Database and sqlitepp::Statement take care of freeing their resources once they are destroyed. You can force them to free their resources using the close
methods.