SQLiteC++
0.5.0
SQLiteC++ is a smart and easy to use C++ SQLite3 wrapper.
|
RAII management of a SQLite Database Connection. More...
#include <Database.h>
Public Member Functions | |
Database (const char *apFilename, const int aFlags=SQLITE_OPEN_READONLY) | |
Open the provided database UTF-8 filename. More... | |
virtual | ~Database (void) throw () |
Close the SQLite database connection. More... | |
int | exec (const char *apQueries) |
Shortcut to execute one or multiple statements without results. More... | |
Column | execAndGet (const char *apQuery) |
Shortcut to execute a one step query and fetch the first column of the result. More... | |
bool | tableExists (const char *apTableName) |
Shortcut to test if a table exists. More... | |
int | setBusyTimeout (int aTimeoutMs) |
Set a busy handler that sleeps for a specified amount of time when a table is locked. More... | |
sqlite3_int64 | getLastInsertRowid (void) const |
Get the rowid of the most recent successful INSERT into the database from the current connection. More... | |
const std::string & | getFilename (void) const |
Return the filename used to open the database. More... | |
const char * | errmsg (void) const |
Return UTF-8 encoded English language explanation of the most recent error. More... | |
Friends | |
class | Statement |
RAII management of a SQLite Database Connection.
A Database object manage a list of all SQLite Statements associated with the underlying SQLite 3 database connection.
Resource Acquisition Is Initialization (RAII) means that the Database Connection is opened in the constructor and closed in the destructor, so that there is no need to worry about memory management or the validity of the underlying SQLite Connection.
Definition at line 29 of file Database.h.
SQLite::Database::Database | ( | const char * | apFilename, |
const int | aFlags = SQLITE_OPEN_READONLY |
||
) |
Open the provided database UTF-8 filename.
Uses sqlite3_open_v2() with readonly default flag, which is the opposite behavior of the old sqlite3_open() function (READWRITE+CREATE). This makes sense if you want to use it on a readonly filesystem or to prevent creation of a void file when a required file is missing.
Exception is thrown in case of error, then the Database object is NOT constructed.
[in] | apFilename | UTF-8 path/uri to the database file ("filename" sqlite3 parameter) |
[in] | aFlags | SQLITE_OPEN_READONLY/SQLITE_OPEN_READWRITE/SQLITE_OPEN_CREATE... |
Definition at line 18 of file Database.cpp.
|
virtual |
Close the SQLite database connection.
All SQLite statements must have been finalized before, so all Statement objects must have been unregistered.
Definition at line 32 of file Database.cpp.
|
inline |
Return UTF-8 encoded English language explanation of the most recent error.
Definition at line 141 of file Database.h.
int SQLite::Database::exec | ( | const char * | apQueries | ) |
Shortcut to execute one or multiple statements without results.
This is useful for any kind of statements other than the Data Query Language (DQL) "SELECT" :
[in] | apQueries | one or multiple UTF-8 encoded, semicolon-separate SQL statements |
SQLite::Exception | in case of error |
Definition at line 41 of file Database.cpp.
Column SQLite::Database::execAndGet | ( | const char * | apQuery | ) |
Shortcut to execute a one step query and fetch the first column of the result.
This is a shortcut to execute a simple statement with a single result. This should be used only for non reusable queries (else you should use a Statement with bind()). This should be used only for queries with expected results (else an exception is fired).
[in] | apQuery | an UTF-8 encoded SQL query |
SQLite::Exception | in case of error |
Definition at line 56 of file Database.cpp.
|
inline |
Return the filename used to open the database.
Definition at line 133 of file Database.h.
|
inline |
Get the rowid of the most recent successful INSERT into the database from the current connection.
Definition at line 125 of file Database.h.
|
inline |
Set a busy handler that sleeps for a specified amount of time when a table is locked.
[in] | aTimeoutMs | Amount of milliseconds to wait before returning SQLITE_BUSY |
Definition at line 115 of file Database.h.
bool SQLite::Database::tableExists | ( | const char * | apTableName | ) |
Shortcut to test if a table exists.
Table names are case sensitive.
[in] | apTableName | an UTF-8 encoded case sensitive Table name |
SQLite::Exception | in case of error |
Definition at line 64 of file Database.cpp.
|
friend |
Definition at line 31 of file Database.h.