SQLamarr
The stand-alone ultra-fast simulation option for the LHCb experiment
SQLamarr::BaseSqlInterface Class Reference

Abstract interface with helper functions to access an SQLite DB. More...

#include <BaseSqlInterface.h>

Inheritance diagram for SQLamarr::BaseSqlInterface:

Public Member Functions

 BaseSqlInterface (SQLite3DB &db)
 Constructor, acquiring the database without ownership. More...
 
virtual ~BaseSqlInterface ()
 

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

SQLite3DBm_database
 Reference to the SQLite database (not owned). More...
 

Detailed Description

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 35 of file BaseSqlInterface.h.

Constructor & Destructor Documentation

◆ BaseSqlInterface()

SQLamarr::BaseSqlInterface::BaseSqlInterface ( SQLite3DB db)

Constructor, acquiring the database without ownership.

Definition at line 22 of file BaseSqlInterface.cpp.

◆ ~BaseSqlInterface()

SQLamarr::BaseSqlInterface::~BaseSqlInterface ( )
virtual

Definition at line 31 of file BaseSqlInterface.cpp.

Member Function Documentation

◆ begin_transaction()

void SQLamarr::BaseSqlInterface::begin_transaction ( )
inlineprotected

Begin an SQL transaction stopping update to disk util end_transaction() is issued

Definition at line 60 of file BaseSqlInterface.h.

◆ end_transaction()

void SQLamarr::BaseSqlInterface::end_transaction ( )
inlineprotected

End an SQL transaction re-enabling disk updates.

Definition at line 63 of file BaseSqlInterface.h.

◆ exec_stmt()

bool SQLamarr::BaseSqlInterface::exec_stmt ( sqlite3_stmt *  stmt)
protected

Execute a statement, possibly throwing an exception on failure.

Definition at line 71 of file BaseSqlInterface.cpp.

◆ get_statement()

sqlite3_stmt * SQLamarr::BaseSqlInterface::get_statement ( const std::string &  name,
const std::string &  query 
)
protected

Creates or retrieve from cache a statement.

Parameters
nameHuman-readable uid of the query used as key in a hash table
querySQL query used to initialize the in case it is not present in cache

Definition at line 40 of file BaseSqlInterface.cpp.

◆ last_insert_row()

int SQLamarr::BaseSqlInterface::last_insert_row ( )
inlineprotected

Return the index of the last rows inserted in any table.

Definition at line 66 of file BaseSqlInterface.h.

◆ using_sql_function()

void SQLamarr::BaseSqlInterface::using_sql_function ( const std::string &  name,
int  argc,
void(*)(sqlite3_context *, int, sqlite3_value **)  xFunc 
)
protected

Register a static function in DB, enabling usage from SQL.

Function prototype should be:

void (sqlite3_context* context, int argc, sqlite3_value** argv);
Parameters
nameName of the SQL function
argcMax. number of arguments
xFuncFunction pointer

Definition at line 55 of file BaseSqlInterface.cpp.

Member Data Documentation

◆ m_database

SQLite3DB& SQLamarr::BaseSqlInterface::m_database
protected

Reference to the SQLite database (not owned).

Definition at line 43 of file BaseSqlInterface.h.


The documentation for this class was generated from the following files: