Abstract interface with helper functions to access an SQLite DB. More...
#include <BaseSqlInterface.h>
Public Member Functions | |
BaseSqlInterface (SQLite3DB &db) | |
Constructor, acquiring the database without ownership. More... | |
virtual | ~BaseSqlInterface () |
void | sync_database (const std::string &db_uri) |
void | invalidate_cache (void) |
Invalidate the cache of the queries. More... | |
Protected Member Functions | |
sqlite3_stmt * | get_statement (const std::string &name, const std::string &query) |
Creates or retrieve from cache a statement. More... | |
void | begin_transaction () |
Begin an SQL transaction stopping update to disk util end_transaction() is issued More... | |
void | end_transaction () |
End an SQL transaction re-enabling disk updates. More... | |
int | last_insert_row () |
Return the index of the last rows inserted in any table. More... | |
void | using_sql_function (const std::string &name, int argc, void(*xFunc)(sqlite3_context *, int, sqlite3_value **)) |
Register a static function in DB, enabling usage from SQL. More... | |
bool | exec_stmt (sqlite3_stmt *) |
Execute a statement, possibly throwing an exception on failure. More... | |
Protected Attributes | |
SQLite3DB & | m_database |
Reference to the SQLite database (not owned). More... | |
Abstract interface with helper functions to access an SQLite DB.
SQLamarr uses SQLite to replace the Transient Event Store of Gaudi and to provide persistency in a consistent, standard format easly read and written in C/C++ and other languages.
The helper class BaseSqlInterface defines helper functions to prepare SQL queries once and run them multiple times on different batches of data.
It also standardize the calls to the BEGIN and END transaction queries that are used to drastically speed up sets of multiple queries when using a database with persistency.
Definition at line 34 of file BaseSqlInterface.h.
SQLamarr::BaseSqlInterface::BaseSqlInterface | ( | SQLite3DB & | db | ) |
Constructor, acquiring the database without ownership.
Definition at line 22 of file BaseSqlInterface.cpp.
|
virtual |
Definition at line 33 of file BaseSqlInterface.cpp.
|
inlineprotected |
Begin an SQL transaction stopping update to disk util end_transaction()
is issued
Definition at line 68 of file BaseSqlInterface.h.
|
inlineprotected |
End an SQL transaction re-enabling disk updates.
Definition at line 71 of file BaseSqlInterface.h.
|
protected |
Execute a statement, possibly throwing an exception on failure.
Definition at line 89 of file BaseSqlInterface.cpp.
|
protected |
Creates or retrieve from cache a statement.
name | Human-readable uid of the query used as key in a hash table |
query | SQL query used to initialize the in case it is not present in cache |
Definition at line 52 of file BaseSqlInterface.cpp.
void SQLamarr::BaseSqlInterface::invalidate_cache | ( | void | ) |
Invalidate the cache of the queries.
Especially useful to allow refreshing the connection when running from Python.
Definition at line 41 of file BaseSqlInterface.cpp.
|
inlineprotected |
Return the index of the last rows inserted in any table.
Definition at line 74 of file BaseSqlInterface.h.
|
inline |
Definition at line 41 of file BaseSqlInterface.h.
|
protected |
Register a static function in DB, enabling usage from SQL.
Function prototype should be:
name | Name of the SQL function |
argc | Max. number of arguments |
xFunc | Function pointer |
Definition at line 73 of file BaseSqlInterface.cpp.
|
protected |
Reference to the SQLite database (not owned).
Definition at line 50 of file BaseSqlInterface.h.