SQLamarr
The stand-alone ultra-fast simulation option for the LHCb experiment
db_functions.h
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 #pragma once
12 #include <memory>
13 #include <string>
14 #include "sqlite3.h"
15 
16 namespace SQLamarr
17 {
19  typedef std::unique_ptr<sqlite3, void(*)(sqlite3*)> SQLite3DB;
20 
23  std::string filename,
24  int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI,
25  std::string init = std::string()
26  );
27 
29  sqlite3_stmt* prepare_statement (SQLite3DB& db, const std::string& query);
30 
32  std::string dump_table(SQLite3DB& db, const std::string& query);
33 
35  float read_as_float(sqlite3_stmt*, int);
36 
38  void validate_token(const std::string& token);
39 
42  SQLite3DB& old_db,
43  const std::string& db_uri,
44  int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI
45  );
46 }
47 
48 
A database connection handler easying sharing the DB between C++ and Python.
Definition: db_functions.py:24
sqlite3_stmt * prepare_statement(SQLite3DB &db, const std::string &query)
Prpare a statement.
void update_db_connection(SQLite3DB &old_db, const std::string &db_uri, int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI)
Force synchronization to disk by closing and opening the connection.
void validate_token(const std::string &token)
Ensure a token is alphanumeric.
SQLite3DB make_database(std::string filename, int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI, std::string init=std::string())
Initialize the database.
float read_as_float(sqlite3_stmt *, int)
Read a column field from a sqlite3 statement and convert it to float.
std::string dump_table(SQLite3DB &db, const std::string &query)
Dump the result of a query to a string.