OpenASIP
2.0
|
#include <SQLiteConnection.hh>
Public Member Functions | |
SQLiteConnection (sqlite3 *connection) | |
virtual | ~SQLiteConnection () |
virtual int | updateQuery (const std::string &queryString) |
virtual void | DDLQuery (const std::string &queryString) |
virtual RelationalDBQueryResult * | query (const std::string &queryString, bool init=true) |
virtual void | beginTransaction () |
virtual void | rollback () |
virtual void | commit () |
virtual RowID | lastInsertRowID () |
virtual bool | tableExistsInDB (const std::string &tableName) |
virtual int | rowCountInTable (const std::string &tableName) |
void | throwIfSQLiteError (int result) |
void | finalizeQuery (sqlite3_stmt *statement) |
virtual int | version () |
virtual void | updateVersion (int version) |
![]() | |
virtual | ~RelationalDBConnection () |
Private Member Functions | |
sqlite3_stmt * | compileQuery (const std::string &queryString) |
Private Attributes | |
sqlite3 * | connection_ |
SQLite connection handle is saved to this. More... | |
bool | transactionActive_ |
Implementation of RelationalDBConnection interface for SQLite library.
Definition at line 47 of file SQLiteConnection.hh.
SQLiteConnection::SQLiteConnection | ( | sqlite3 * | connection | ) |
Constructor.
connection | A pointer to a SQLite connection handle. |
Definition at line 45 of file SQLiteConnection.cc.
|
virtual |
Destructor.
Closes the connection.
Definition at line 54 of file SQLiteConnection.cc.
References connection_.
|
virtual |
Starts a new database transaction.
Also ends the possible previous transaction successfully (commit).
RelationalDBException | In case a database error occured. |
Implements RelationalDBConnection.
Definition at line 124 of file SQLiteConnection.cc.
References commit(), transactionActive_, and updateQuery().
|
virtual |
Ends the current database transaction successfully and commits all the changes in the transaction to the database.
RelationalDBException | In case a database error occured. |
Implements RelationalDBConnection.
Definition at line 151 of file SQLiteConnection.cc.
References transactionActive_, and updateQuery().
Referenced by beginTransaction().
|
private |
Compiles a SQLite query.
queryString | The SQL statement to compile. |
RelationalDBException | In case a database error occured. |
Definition at line 270 of file SQLiteConnection.cc.
References connection_, dummy, and throwIfSQLiteError().
Referenced by query(), and updateQuery().
|
virtual |
Performs a SQL Data Definition Language query, that is a query that may change the structure of the database (CREATE TABLE, etc.).
Does not autocommit the changes in case the update is in the middle of transaction.
queryString | The query string. |
RelationalDBException | In case a database error occured. |
Implements RelationalDBConnection.
Definition at line 98 of file SQLiteConnection.cc.
References updateQuery().
void SQLiteConnection::finalizeQuery | ( | sqlite3_stmt * | statement | ) |
Finalizes a SQLite query, frees the virtual machine.
Does nothing if the statement is NULL.
statement | The SQLite statement to free. |
RelationalDBException | In case there was errors (can be cumulated from a previous sqlite3_step() call). |
Definition at line 291 of file SQLiteConnection.cc.
References throwIfSQLiteError().
Referenced by updateQuery(), and SQLiteQueryResult::~SQLiteQueryResult().
|
virtual |
Returns the row ID of the most recent insert in the database.
Implements RelationalDBConnection.
Definition at line 162 of file SQLiteConnection.cc.
References connection_.
|
virtual |
Performs a data retrieval query (SELECT).
queryString | The query string. |
RelationalDBException | In case a database error occured. |
Implements RelationalDBConnection.
Definition at line 110 of file SQLiteConnection.cc.
References compileQuery().
Referenced by rowCountInTable(), tableExistsInDB(), updateVersion(), and version().
|
virtual |
Ends the current database transaction unsuccessfully and rollbacks all the changes the queries in the transaction would have done.
RelationalDBException | In case a database error occured. |
Implements RelationalDBConnection.
Definition at line 139 of file SQLiteConnection.cc.
References transactionActive_, and updateQuery().
|
virtual |
Return number of entries in the given table.
tableName | Name of the table. |
RelationalDBException | In case a database error occurred, call was made in the middle of an active transaction or the table does not exists. |
Implements RelationalDBConnection.
Definition at line 218 of file SQLiteConnection.cc.
References assert, RelationalDBQueryResult::data(), Exception::errorMessage(), RelationalDBQueryResult::hasNext(), DataObject::integerValue(), RelationalDBQueryResult::next(), query(), and tableExistsInDB().
|
virtual |
Checks if database has given table by name.
tableName | Name of the table |
RelationalDBException | In case a database error occurred or call was made in the middle of an active transaction. |
Implements RelationalDBConnection.
Definition at line 177 of file SQLiteConnection.cc.
References assert, RelationalDBQueryResult::data(), Exception::errorMessage(), RelationalDBQueryResult::hasNext(), DataObject::integerValue(), RelationalDBQueryResult::next(), query(), and transactionActive_.
Referenced by rowCountInTable().
void SQLiteConnection::throwIfSQLiteError | ( | int | result | ) |
Throws a RelationalDBException if result value indicates an SQLite error.
result | The value from a SQLite API call. |
RelationalDBException | Thrown if result is not SQLITE_OK. |
Definition at line 253 of file SQLiteConnection.cc.
References connection_.
Referenced by SQLiteQueryResult::bindInt(), SQLiteQueryResult::bindString(), compileQuery(), finalizeQuery(), SQLiteQueryResult::reset(), and updateQuery().
|
virtual |
Performs a query that changes the database (UPDATE/INSERT/DELETE).
Does not autocommit the changes in case the update is in the middle of transaction.
queryString | The query string. |
RelationalDBException | In case a database error occured. |
Implements RelationalDBConnection.
Definition at line 69 of file SQLiteConnection.cc.
References assert, compileQuery(), connection_, finalizeQuery(), and throwIfSQLiteError().
Referenced by beginTransaction(), commit(), DDLQuery(), rollback(), and updateVersion().
|
virtual |
Set database version number.
version | New database version. |
Implements RelationalDBConnection.
Definition at line 335 of file SQLiteConnection.cc.
References query(), updateQuery(), and version().
|
virtual |
Return database version number.
Implements RelationalDBConnection.
Definition at line 305 of file SQLiteConnection.cc.
References assert, RelationalDBQueryResult::data(), Exception::errorMessage(), RelationalDBQueryResult::hasNext(), DataObject::integerValue(), RelationalDBQueryResult::next(), and query().
Referenced by updateVersion().
|
private |
SQLite connection handle is saved to this.
Definition at line 78 of file SQLiteConnection.hh.
Referenced by compileQuery(), lastInsertRowID(), throwIfSQLiteError(), updateQuery(), and ~SQLiteConnection().
|
private |
Definition at line 80 of file SQLiteConnection.hh.
Referenced by beginTransaction(), commit(), rollback(), and tableExistsInDB().