SQLite prepared statement.
More...
#include <Statement.h>
|
| void | reset () |
| | Reset prepared statement for re-execution and clear bindings.
|
| bool | step () |
| | Step through the prepared statement.
|
| void | bind (int index, std::int64_t value) |
| | Bind an integer to a parameter.
|
template<typename I>
requires std::integral<I> |
| void | bind (int index, I value) |
| void | bind (int index, double value) |
| | Bind a double to a parameter.
|
| void | bind (int index, std::string_view value) |
| | Bind a string to a parameter.
|
| template<ValidColumnType T, std::size_t I> |
| T | column () |
| | Retrieve a column.
|
| template<ValidColumnType... Ts, std::size_t... Is> |
| std::tuple< Ts... > | columns (std::index_sequence< Is... >) |
| | Retrieve columns.
|
SQLite prepared statement.
Definition at line 50 of file Statement.h.
◆ Statement() [1/3]
| SQLite::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 createStatement member function of SQLiteDBSvc.
Definition at line 12 of file Statement.cxx.
16 sqlite3_prepare_v2(db,
sql.data(),
int(
sql.size()), &
m_stmt,
nullptr);
17 if (err != 0) {
18 throw std::logic_error(
19 std::format("ERROR preparing SQLite statement: {} ({}) at {} [{}:{}]",
20 sqlite3_errstr(err), sqlite3_errmsg(
m_db),
23 }
24}
std::source_location m_creationPoint
◆ ~Statement()
| SQLite::Statement::~Statement |
( |
| ) |
|
◆ Statement() [2/3]
| SQLite::Statement::Statement |
( |
| ) |
|
|
default |
◆ Statement() [3/3]
| SQLite::Statement::Statement |
( |
const Statement & | | ) |
|
|
delete |
◆ bind() [1/4]
| void SQLite::Statement::bind |
( |
int | index, |
|
|
double | value ) |
|
private |
Bind a double to a parameter.
Definition at line 80 of file Statement.cxx.
80 {
81 const int err = sqlite3_bind_double(
m_stmt, index, value);
82 if (err != 0) {
83 throw std::tuple<int, int>{
err,
index};
84 }
85}
◆ bind() [2/4]
template<typename
I>
requires std::integral<
I>
| void SQLite::Statement::bind |
( |
int | index, |
|
|
I | value ) |
|
private |
◆ bind() [3/4]
| void SQLite::Statement::bind |
( |
int | index, |
|
|
std::int64_t | value ) |
|
private |
Bind an integer to a parameter.
Definition at line 73 of file Statement.cxx.
73 {
74 const int err = sqlite3_bind_int64(
m_stmt, index, value);
75 if (err != 0) {
76 throw std::tuple<int, int>{
err,
index};
77 }
78}
◆ bind() [4/4]
| void SQLite::Statement::bind |
( |
int | index, |
|
|
std::string_view | value ) |
|
private |
Bind a string to a parameter.
Definition at line 87 of file Statement.cxx.
87 {
89 int(
value.size()), SQLITE_TRANSIENT);
90 if (err != 0) {
91 throw std::tuple<int, int>{
err,
index};
92 }
93}
◆ column()
template<ValidColumnType T, std::size_t I>
| T SQLite::Statement::column |
( |
| ) |
|
|
private |
◆ columns()
template<ValidColumnType... Ts, std::size_t... Is>
| std::tuple< Ts... > SQLite::Statement::columns |
( |
std::index_sequence< Is... > | | ) |
|
|
private |
◆ operator=()
Move assignment operator allows Statement member variables to be filled from createStatement.
Definition at line 26 of file Statement.cxx.
26 {
31 rhs.m_stmt = nullptr;
32 rhs.m_db = nullptr;
33 return *this;
34}
std::recursive_mutex m_stmtMutex
◆ reset()
| void SQLite::Statement::reset |
( |
| ) |
|
|
private |
Reset prepared statement for re-execution and clear bindings.
Definition at line 44 of file Statement.cxx.
44 {
46 if (err != 0) {
47 throw std::runtime_error(
48 std::format("ERROR in SQLite statement reset: {} ({})",
49 sqlite3_errstr(err), sqlite3_errmsg(
m_db)));
50 }
51 sqlite3_clear_bindings(
m_stmt);
52}
◆ run()
template<ValidColumnType... ReturnArgs, ValidParamType... ParamArgs>
◆ step()
| bool SQLite::Statement::step |
( |
| ) |
|
|
private |
Step through the prepared statement.
Definition at line 54 of file Statement.cxx.
54 {
55 int err = SQLITE_BUSY;
56 while (err == SQLITE_BUSY) {
58 }
59 switch (err) {
60 case SQLITE_DONE:
61 return false;
62 case SQLITE_ROW:
63 return true;
64 default:
65 throw std::runtime_error(
66 std::format("ERROR in SQLite statement step: {} ({})",
67 sqlite3_errstr(err), sqlite3_errmsg(
m_db)));
68 }
69}
◆ m_creationPoint
| std::source_location SQLite::Statement::m_creationPoint |
|
private |
◆ m_db
| sqlite3* SQLite::Statement::m_db = nullptr |
|
private |
◆ m_stmt
| sqlite3_stmt* SQLite::Statement::m_stmt = nullptr |
|
private |
◆ m_stmtMutex
| std::recursive_mutex SQLite::Statement::m_stmtMutex |
|
private |
The documentation for this class was generated from the following files: