ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
SQLiteDBSvc
SQLiteDBSvc
Statement.h
Go to the documentation of this file.
1
/* -*- C++ -*- */
2
/*
3
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4
*/
5
#ifndef SQLITEDBSVC_STATEMENT_H
6
#define SQLITEDBSVC_STATEMENT_H
7
8
#include <concepts>
9
#include <mutex>
10
#include <source_location>
// Improves error messages
11
#include <string>
12
#include <string_view>
13
#include <tuple>
14
#include <vector>
15
16
#include "sqlite3.h"
17
18
namespace
SQLite
{
20
template
<
typename
T>
21
concept
ValidParamType
=
requires
{
22
requires
std::convertible_to<T, std::int64_t> ||
23
std::convertible_to<T, double> ||
24
std::convertible_to<T, std::string_view>;
25
};
26
28
template
<
typename
T>
29
concept
ValidColumnType
=
requires
{
30
requires
std::same_as<std::remove_cvref_t<T>, T> &&
31
(std::is_arithmetic_v<T> || std::same_as<T, std::string>);
32
};
33
35
template
<
ValidColumnType
...
Args
>
36
requires
(
sizeof
...(Args) >= 1)
37
using
ResultType
= std::vector<std::tuple<Args...>>;
38
40
template
<
typename
...
Args
>
41
struct
ResultTypeWrapper
{
42
using
type
=
ResultType
<
Args
...>;
43
};
44
template
<>
45
struct
ResultTypeWrapper
<> {
46
using
type
= void;
47
};
48
50
class
Statement
{
51
public
:
55
Statement
(sqlite3* db, std::string_view sql, std::source_location call);
56
~Statement
();
57
Statement
() =
default
;
58
Statement
(
const
Statement
&) =
delete
;
59
62
Statement
&
operator=
(
Statement
&& rhs)
noexcept
;
63
65
template
<
ValidColumnType
... ReturnArgs,
ValidParamType
... ParamArgs>
66
ResultTypeWrapper
<ReturnArgs...>
::type
run
(ParamArgs... params);
67
68
private
:
70
void
reset
();
72
bool
step
();
73
75
void
bind
(
int
index
, std::int64_t value);
76
// template to force the correct overload to be called for ints
77
template
<
typename
I>
78
requires
std::integral<I>
79
void
bind
(
int
index
,
I
value);
81
void
bind
(
int
index
,
double
value);
83
void
bind
(
int
index
, std::string_view value);
84
86
template
<Val
id
ColumnType T, std::
size_t
I>
87
T
column
();
89
template
<
ValidColumnType
... Ts, std::size_t... Is>
90
std::tuple<Ts...>
columns
(std::index_sequence<Is...>);
91
92
std::recursive_mutex
m_stmtMutex
;
93
sqlite3_stmt*
m_stmt
=
nullptr
;
94
sqlite3*
m_db
=
nullptr
;
95
std::source_location
m_creationPoint
;
96
};
97
}
// namespace SQLite
98
99
#include "
Statement.icc
"
100
#endif
// SQLITEDBSVC_STATEMENT_H
I
#define I(x, y, z)
Definition
MD5.cxx:116
Statement.icc
SQLite::Statement::Statement
Statement()=default
SQLite::Statement::columns
std::tuple< Ts... > columns(std::index_sequence< Is... >)
Retrieve columns.
SQLite::Statement::reset
void reset()
Reset prepared statement for re-execution and clear bindings.
Definition
Statement.cxx:44
SQLite::Statement::~Statement
~Statement()
Definition
Statement.cxx:36
SQLite::Statement::m_db
sqlite3 * m_db
Definition
Statement.h:94
SQLite::Statement::operator=
Statement & operator=(Statement &&rhs) noexcept
Move assignment operator allows Statement member variables to be filled from createStatement.
Definition
Statement.cxx:26
SQLite::Statement::Statement
Statement(sqlite3 *db, std::string_view sql, std::source_location call)
Create a prepared statement attached to an SQLiteDBSvc This class should be constructed using the cre...
Definition
Statement.cxx:12
SQLite::Statement::Statement
Statement(const Statement &)=delete
SQLite::Statement::m_stmt
sqlite3_stmt * m_stmt
Definition
Statement.h:93
SQLite::Statement::bind
void bind(int index, std::int64_t value)
Bind an integer to a parameter.
Definition
Statement.cxx:73
SQLite::Statement::column
T column()
Retrieve a column.
SQLite::Statement::bind
void bind(int index, I value)
SQLite::Statement::m_stmtMutex
std::recursive_mutex m_stmtMutex
Definition
Statement.h:92
SQLite::Statement::run
ResultTypeWrapper< ReturnArgs... >::type run(ParamArgs... params)
Run the statement.
SQLite::Statement::m_creationPoint
std::source_location m_creationPoint
Definition
Statement.h:95
SQLite::Statement::step
bool step()
Step through the prepared statement.
Definition
Statement.cxx:54
SQLite::ValidColumnType
Test if a type is a valid placeholder for some SQLite column type.
Definition
Statement.h:29
SQLite::ValidParamType
Test if a type is a valid SQLite parameter type.
Definition
Statement.h:21
SQLite
Definition
Statement.h:18
SQLite::ResultType
std::vector< std::tuple< Args... > > ResultType
Return type for result of an SQL statement that returns data.
Definition
Statement.h:37
index
Definition
index.py:1
Args
Definition
test_lwtnn_fastgraph.cxx:12
type
SQLite::ResultTypeWrapper<>::type
void type
Definition
Statement.h:46
SQLite::ResultTypeWrapper
Helper to return void if Args is empty or void.
Definition
Statement.h:41
SQLite::ResultTypeWrapper::type
ResultType< Args... > type
Definition
Statement.h:42
Generated on
for ATLAS Offline Software by
1.17.0