SQLamarr
The stand-alone ultra-fast simulation option for the LHCb experiment
EditEventStore.cpp
1 // (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration.
2 //
3 // This software is distributed under the terms of the GNU General Public
4 // Licence version 3 (GPL Version 3), copied verbatim in the file "LICENCE".
5 //
6 // In applying this licence, CERN does not waive the privileges and immunities
7 // granted to it by virtue of its status as an Intergovernmental Organization
8 // or submit itself to any jurisdiction.
9 
10 
11 // STL
12 #include <iostream>
13 #include <algorithm>
14 
15 // SQLite3
16 #include "sqlite3.h"
17 
18 // SQLamarr
19 #include "SQLamarr/EditEventStore.h"
20 
21 namespace SQLamarr
22 {
23  //============================================================================
24  // Constructor
25  //============================================================================
27  SQLite3DB& db,
28  const std::vector<std::string>& queries
29  )
30  : BaseSqlInterface(db)
31  , m_queries (queries)
32  {}
33 
34  //============================================================================
35  // execute
36  //============================================================================
38  {
39  int counter = 0;
40  char buffer[1024];
41  exec_stmt(get_statement("BEGIN", "BEGIN EXCLUSIVE TRANSACTION"));
42  for (auto& query: m_queries)
43  {
44  sprintf(buffer, "EditEventStore%02d", counter++);
45  exec_stmt(get_statement(buffer, query.c_str()));
46  }
47 
48  exec_stmt(get_statement("COMMIT", "COMMIT TRANSACTION"));
49  }
50 }
51 
Abstract interface with helper functions to access an SQLite DB.
sqlite3_stmt * get_statement(const std::string &name, const std::string &query)
Creates or retrieve from cache a statement.
bool exec_stmt(sqlite3_stmt *)
Execute a statement, possibly throwing an exception on failure.
EditEventStore(SQLite3DB &db, const std::vector< std::string > &queries)
Constructor.
void execute() override
Execute the algorithm, cleaning the database.
A database connection handler easying sharing the DB between C++ and Python.
Definition: db_functions.py:24