ATLAS Offline Software
Loading...
Searching...
No Matches
SQLiteDBSvc Class Reference

A service to manage a connection to an SQLite DB. More...

#include <SQLiteDBSvc.h>

Inheritance diagram for SQLiteDBSvc:
Collaboration diagram for SQLiteDBSvc:

Public Member Functions

 SQLiteDBSvc (const std::string &name, ISvcLocator *svcLoc)
 Constructor.
virtual StatusCode initialize () override
 Initialize.
virtual SQLite::Statement createStatement (std::string_view statement, std::source_location call=std::source_location::current()) override
 Compile a prepared statement attached to this database.

Private Attributes

std::unique_ptr< sqlite3, int(*)(sqlite3 *)> m_db ATLAS_THREAD_SAFE
Gaudi::Property< std::string > m_databasePath

Detailed Description

A service to manage a connection to an SQLite DB.

Definition at line 21 of file SQLiteDBSvc.h.

Constructor & Destructor Documentation

◆ SQLiteDBSvc()

SQLiteDBSvc::SQLiteDBSvc ( const std::string & name,
ISvcLocator * svcLoc )
inline

Constructor.

Definition at line 24 of file SQLiteDBSvc.h.

25 : extends(name, svcLoc), m_db(nullptr, sqlite3_close_v2) {}

Member Function Documentation

◆ createStatement()

SQLite::Statement SQLiteDBSvc::createStatement ( std::string_view statement,
std::source_location call = std::source_location::current() )
overridevirtual

Compile a prepared statement attached to this database.

The service will manage the statement object and delete it in finalize. Statements are protected by a mutex and may be used from multiple threads. It's reasonable to construct all the prepared statements you might need in a service or algorithm initialize.

Parameters
[in]statementSQL statement to be compiled

Definition at line 22 of file SQLiteDBSvc.cxx.

23 {
24 return SQLite::Statement(m_db.get(), statement, call);
25}

◆ initialize()

StatusCode SQLiteDBSvc::initialize ( )
overridevirtual

Initialize.

Definition at line 7 of file SQLiteDBSvc.cxx.

7 {
8 sqlite3* temp = nullptr;
9 const int err = sqlite3_open_v2(m_databasePath.value().c_str(), &temp,
10 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
11 SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_URI,
12 nullptr);
13 if (err != 0) {
14 ATH_MSG_ERROR("Error opening SQLite DB: << " << sqlite3_errstr(err));
15 return StatusCode::FAILURE;
16 }
17 m_db.reset(temp);
18 ATH_MSG_INFO("Opened db connection to " << m_databasePath.value().c_str());
19 return StatusCode::SUCCESS;
20}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
Gaudi::Property< std::string > m_databasePath
Definition SQLiteDBSvc.h:42

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::unique_ptr<sqlite3, int (*)(sqlite3*)> m_db SQLiteDBSvc::ATLAS_THREAD_SAFE
private

Definition at line 41 of file SQLiteDBSvc.h.

◆ m_databasePath

Gaudi::Property<std::string> SQLiteDBSvc::m_databasePath
private
Initial value:
{
this, "DatabasePath", ":memory:",
"Path to SQLite Database. The default (:memory:) creates a temporary "
"in-memory database. Options may be set using SQLite URI filenames."}

Definition at line 42 of file SQLiteDBSvc.h.

42 {
43 this, "DatabasePath", ":memory:",
44 "Path to SQLite Database. The default (:memory:) creates a temporary "
45 "in-memory database. Options may be set using SQLite URI filenames."};

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