KaliVeda
Toolkit for HIC analysis
KVSQLiteServer Class Reference

Detailed Description

Modified copy of TSQLiteServer.

The Query(), Exec() and Statement() methods have been modified so that in case an error occurs, it can be retrieved after the call with GetErrorCode() (TSQLiteServer does not store the error codes internally).

The TSQLServer::GetTablesList() method is overridden so that if the database is locked by another process/thread, we try again a maximum of 4 times with a sleep of 50 ms between each attempt.

Definition at line 31 of file KVSQLiteServer.h.

#include <KVSQLiteServer.h>

Inheritance diagram for KVSQLiteServer:

Public Member Functions

 KVSQLiteServer (const char *db, const char *uid=nullptr, const char *pw=nullptr)
 
 ~KVSQLiteServer ()
 Close SQLite DB. More...
 
 ClassDefOverride (KVSQLiteServer, 0)
 
void Close (Option_t *opt="") final
 Close connection to SQLite DB. More...
 
Bool_t Commit () final
 
Int_t CreateDataBase (const char *dbname) final
 
Int_t DropDataBase (const char *dbname) final
 
Bool_t Exec (const char *sql) final
 
TSQLResultGetColumns (const char *dbname, const char *table, const char *wild=nullptr) final
 
TSQLResultGetDataBases (const char *wild=nullptr) final
 
TSQLTableInfoGetTableInfo (const char *tablename) final
 
TSQLResultGetTables (const char *dbname, const char *wild=nullptr) final
 
TListGetTablesList (const char *wild=nullptr) final
 
Bool_t HasStatement () const final
 
Bool_t HasTransactionInFlight () final
 returns kTRUE when transaction is running More...
 
bool IsLocked () const
 
bool IsOK () const
 
TSQLResultQuery (const char *sql) final
 
Int_t Reload () final
 
Bool_t Rollback () final
 
Int_t SelectDataBase (const char *dbname) final
 
const char * ServerInfo () final
 Return server info, must be deleted by user. More...
 
Int_t Shutdown () final
 
Bool_t StartTransaction () final
 
TSQLStatementStatement (const char *sql, Int_t=100) final
 Produce TSQLiteStatement. More...
 
- Public Member Functions inherited from TSQLServer
virtual ~TSQLServer ()
 
virtual void EnableErrorOutput (Bool_t on=kTRUE)
 
const char * GetDB () const
 
const char * GetDBMS () const
 
virtual Int_t GetErrorCode () const
 
virtual const char * GetErrorMsg () const
 
const char * GetHost () const
 
virtual Int_t GetMaxIdentifierLength ()
 
Int_t GetPort () const
 
virtual Bool_t HasTable (const char *tablename)
 
TClassIsA () const override
 
virtual Bool_t IsConnected () const
 
virtual Bool_t IsError () const
 
virtual Int_t Ping ()
 
virtual Bool_t PingVerify ()
 
void Streamer (TBuffer &) override
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TObject
 TObject ()
 
 TObject (const TObject &object)
 
virtual ~TObject ()
 
void AbstractMethod (const char *method) const
 
virtual void AppendPad (Option_t *option="")
 
virtual void Browse (TBrowser *b)
 
ULong_t CheckedHash ()
 
virtual const char * ClassName () const
 
virtual void Clear (Option_t *="")
 
virtual TObjectClone (const char *newname="") const
 
virtual Int_t Compare (const TObject *obj) const
 
virtual void Copy (TObject &object) const
 
virtual void Delete (Option_t *option="")
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 
virtual void Draw (Option_t *option="")
 
virtual void DrawClass () const
 
virtual TObjectDrawClone (Option_t *option="") const
 
virtual void Dump () const
 
virtual void Error (const char *method, const char *msgfmt,...) const
 
virtual void Execute (const char *method, const char *params, Int_t *error=nullptr)
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr)
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 
virtual TObjectFindObject (const char *name) const
 
virtual TObjectFindObject (const TObject *obj) const
 
virtual Option_tGetDrawOption () const
 
virtual const char * GetIconName () const
 
virtual const char * GetName () const
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 
virtual Option_tGetOption () const
 
virtual const char * GetTitle () const
 
virtual UInt_t GetUniqueID () const
 
virtual Bool_t HandleTimer (TTimer *timer)
 
virtual ULong_t Hash () const
 
Bool_t HasInconsistentHash () const
 
virtual void Info (const char *method, const char *msgfmt,...) const
 
virtual Bool_t InheritsFrom (const char *classname) const
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 
virtual void Inspect () const
 
void InvertBit (UInt_t f)
 
Bool_t IsDestructed () const
 
virtual Bool_t IsEqual (const TObject *obj) const
 
virtual Bool_t IsFolder () const
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
virtual Bool_t IsSortable () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
virtual void ls (Option_t *option="") const
 
void MayNotUse (const char *method) const
 
virtual Bool_t Notify ()
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 
void operator delete (void *ptr)
 
void operator delete (void *ptr, void *vp)
 
void operator delete[] (void *ptr)
 
void operator delete[] (void *ptr, void *vp)
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 
virtual void Paint (Option_t *option="")
 
virtual void Pop ()
 
virtual void Print (Option_t *option="") const
 
virtual Int_t Read (const char *name)
 
virtual void RecursiveRemove (TObject *obj)
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 
virtual void SetDrawOption (Option_t *option="")
 
virtual void SetUniqueID (UInt_t uid)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 
virtual Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
 
virtual Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const
 

Private Attributes

sqlite3 * fSQLite {nullptr}
 
TString fSrvInfo
 Server info string. More...
 

Additional Inherited Members

- Public Types inherited from TSQLServer
enum  ESQLDataTypes
 
- Public Types inherited from TObject
enum  EDeprecatedStatusBits
 
enum  EStatusBits
 
- Static Public Member Functions inherited from TSQLServer
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static TSQLServerConnect (const char *db, const char *uid, const char *pw)
 
static const char * DeclFileName ()
 
static const char * GetFloatFormat ()
 
static void SetFloatFormat (const char *fmt="%e")
 
- Static Public Member Functions inherited from TObject
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Longptr_t GetDtorOnly ()
 
static Bool_t GetObjectStat ()
 
static void SetDtorOnly (void *obj)
 
static void SetObjectStat (Bool_t stat)
 
- Public Attributes inherited from TSQLServer
 kSQL_BINARY
 
 kSQL_CHAR
 
 kSQL_DOUBLE
 
 kSQL_FLOAT
 
 kSQL_INTEGER
 
 kSQL_NONE
 
 kSQL_NUMERIC
 
 kSQL_TIMESTAMP
 
 kSQL_VARCHAR
 
- Public Attributes inherited from TObject
 kBitMask
 
 kCanDelete
 
 kCannotPick
 
 kHasUUID
 
 kInconsistent
 
 kInvalidObject
 
 kIsOnHeap
 
 kIsReferenced
 
 kMustCleanup
 
 kNoContextMenu
 
 kNotDeleted
 
 kObjInCanvas
 
 kOverwrite
 
 kSingleKey
 
 kWriteDelete
 
 kZombie
 
- Protected Member Functions inherited from TSQLServer
 TSQLServer ()
 
void ClearError ()
 
void SetError (Int_t code, const char *msg, const char *method=nullptr)
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 
void MakeZombie ()
 
- Protected Attributes inherited from TSQLServer
TString fDB
 
Int_t fErrorCode
 
TString fErrorMsg
 
Bool_t fErrorOut
 
TString fHost
 
Int_t fPort
 
TString fType
 
- Protected Attributes inherited from TObject
 kOnlyPrepStep
 
- Static Protected Attributes inherited from TSQLServer
static const char * fgFloatFmt
 

Constructor & Destructor Documentation

◆ KVSQLiteServer()

KVSQLiteServer::KVSQLiteServer ( const char *  db,
const char *  uid = nullptr,
const char *  pw = nullptr 
)

Open a connection to an SQLite DB server. The db arguments should be of the form "sqlite://<database>", e.g.: "sqlite://test.sqlite" or "sqlite://:memory:" for a temporary database in memory. Note that for SQLite versions >= 3.7.7 the full string behind "sqlite://" is handed to sqlite3_open_v2() with SQLITE_OPEN_URI activated, so all URI accepted by it can be used.

Definition at line 40 of file KVSQLiteServer.cxx.

◆ ~KVSQLiteServer()

KVSQLiteServer::~KVSQLiteServer ( )

Close SQLite DB.

Definition at line 88 of file KVSQLiteServer.cxx.

Member Function Documentation

◆ ClassDefOverride()

KVSQLiteServer::ClassDefOverride ( KVSQLiteServer  ,
 
)

◆ Close()

void KVSQLiteServer::Close ( Option_t opt = "")
finalvirtual

Close connection to SQLite DB.

Implements TSQLServer.

Definition at line 102 of file KVSQLiteServer.cxx.

◆ Commit()

Bool_t KVSQLiteServer::Commit ( )
finalvirtual

submit "COMMIT TRANSACTION" query to database return kTRUE, if successful

Reimplemented from TSQLServer.

Definition at line 154 of file KVSQLiteServer.cxx.

◆ CreateDataBase()

Int_t KVSQLiteServer::CreateDataBase ( const char *  dbname)
finalvirtual

Create a database. Always returns non-zero for SQLite, as it has only one DB per file.

Implements TSQLServer.

Definition at line 407 of file KVSQLiteServer.cxx.

◆ DropDataBase()

Int_t KVSQLiteServer::DropDataBase ( const char *  dbname)
finalvirtual

Drop (i.e. delete) a database. Always returns non-zero for SQLite, as it has only one DB per file.

Implements TSQLServer.

Definition at line 421 of file KVSQLiteServer.cxx.

◆ Exec()

Bool_t KVSQLiteServer::Exec ( const char *  sql)
finalvirtual

Execute SQL command which does not produce any result sets. Returns kTRUE if successful.

Reimplemented from TSQLServer.

Definition at line 216 of file KVSQLiteServer.cxx.

◆ GetColumns()

TSQLResult * KVSQLiteServer::GetColumns ( const char *  dbname,
const char *  table,
const char *  wild = nullptr 
)
finalvirtual

List all columns in specified table (database argument is ignored). Wild is for wildcarding "t%" list all columns starting with "t". Returns a pointer to a TSQLResult object if successful, 0 otherwise. The result object must be deleted by the user. For SQLite, this fails with wildcard, as the column names are not queryable! If no wildcard is used, the result of PRAGMA table_info(table) is returned, which contains the names in field 1.

Implements TSQLServer.

Definition at line 326 of file KVSQLiteServer.cxx.

◆ GetDataBases()

TSQLResult * KVSQLiteServer::GetDataBases ( const char *  wild = nullptr)
finalvirtual

List all available databases. Always returns 0 for SQLite, as only one DB exists per file.

Implements TSQLServer.

Definition at line 255 of file KVSQLiteServer.cxx.

◆ GetTableInfo()

TSQLTableInfo * KVSQLiteServer::GetTableInfo ( const char *  tablename)
finalvirtual

Produces SQL table info. Object must be deleted by user.

Reimplemented from TSQLServer.

Definition at line 352 of file KVSQLiteServer.cxx.

◆ GetTables()

TSQLResult * KVSQLiteServer::GetTables ( const char *  dbname,
const char *  wild = nullptr 
)
finalvirtual

List all tables in the specified database. Wild is for wildcarding "t%" list all tables starting with "t". Returns a pointer to a TSQLResult object if successful, 0 otherwise. The result object must be deleted by the user.

Implements TSQLServer.

Definition at line 271 of file KVSQLiteServer.cxx.

◆ GetTablesList()

TList * KVSQLiteServer::GetTablesList ( const char *  wild = nullptr)
finalvirtual

Reimplemented from TSQLServer.

Definition at line 289 of file KVSQLiteServer.cxx.

◆ HasStatement()

Bool_t KVSQLiteServer::HasStatement ( ) const
finalvirtual

We assume prepared statements work for all SQLite-versions. As we actually use the recommended sqlite3_prepare(), or, if possible, sqlite3_prepare_v2(), this already introduces the "compile time check".

Reimplemented from TSQLServer.

Definition at line 475 of file KVSQLiteServer.cxx.

◆ HasTransactionInFlight()

Bool_t KVSQLiteServer::HasTransactionInFlight ( )
finalvirtual

returns kTRUE when transaction is running

Reimplemented from TSQLServer.

Definition at line 137 of file KVSQLiteServer.cxx.

◆ IsLocked()

bool KVSQLiteServer::IsLocked ( ) const

Definition at line 545 of file KVSQLiteServer.cxx.

◆ IsOK()

bool KVSQLiteServer::IsOK ( ) const

Definition at line 554 of file KVSQLiteServer.cxx.

◆ Query()

TSQLResult * KVSQLiteServer::Query ( const char *  sql)
finalvirtual

Execute SQL command. Result object must be deleted by the user. Returns a pointer to a TSQLResult object if successful, 0 otherwise. The result object must be deleted by the user.

Implements TSQLServer.

Definition at line 181 of file KVSQLiteServer.cxx.

◆ Reload()

Int_t KVSQLiteServer::Reload ( )
finalvirtual

Reload permission tables. Returns 0 if successful, non-zero otherwise. User must have reload permissions.

Implements TSQLServer.

Definition at line 435 of file KVSQLiteServer.cxx.

◆ Rollback()

Bool_t KVSQLiteServer::Rollback ( )
finalvirtual

submit "ROLLBACK TRANSACTION" query to database return kTRUE, if successful

Reimplemented from TSQLServer.

Definition at line 167 of file KVSQLiteServer.cxx.

◆ SelectDataBase()

Int_t KVSQLiteServer::SelectDataBase ( const char *  dbname)
finalvirtual

Select a database. Always returns non-zero for SQLite, as only one DB exists per file.

Implements TSQLServer.

Definition at line 241 of file KVSQLiteServer.cxx.

◆ ServerInfo()

const char * KVSQLiteServer::ServerInfo ( )
finalvirtual

Return server info, must be deleted by user.

Implements TSQLServer.

Definition at line 531 of file KVSQLiteServer.cxx.

◆ Shutdown()

Int_t KVSQLiteServer::Shutdown ( )
finalvirtual

Shutdown the database server. Returns 0 if successful, non-zero otherwise. Makes no sense for SQLite, always returns -1.

Implements TSQLServer.

Definition at line 454 of file KVSQLiteServer.cxx.

◆ StartTransaction()

Bool_t KVSQLiteServer::StartTransaction ( )
finalvirtual

submit "BEGIN TRANSACTION" query to database return kTRUE, if successful

Reimplemented from TSQLServer.

Definition at line 124 of file KVSQLiteServer.cxx.

◆ Statement()

TSQLStatement * KVSQLiteServer::Statement ( const char *  sql,
Int_t  = 100 
)
finalvirtual

Produce TSQLiteStatement.

Reimplemented from TSQLServer.

Definition at line 487 of file KVSQLiteServer.cxx.

Member Data Documentation

◆ fSQLite

sqlite3* KVSQLiteServer::fSQLite {nullptr}
private

Definition at line 35 of file KVSQLiteServer.h.

◆ fSrvInfo

TString KVSQLiteServer::fSrvInfo
private

Server info string.

Definition at line 34 of file KVSQLiteServer.h.