Belle II Software light-2406-ragdoll
ParameterBinder Class Reference

Bind the given parameter to the sqlite statement. More...

#include <sqlite.h>

Public Member Functions

 ParameterBinder (sqlite3_stmt *statement)
 Create a new object for the given statement.
 
template<class T >
void operator() (int index, T &&param)
 Bind the parameter with the given index to the statement.
 

Private Member Functions

int bind (int index, int param)
 bind an integer parameter
 
int bind (int index, int64_t param)
 bind a 64bit integer parameter
 
int bind (int index, double param)
 bind a double parameter
 
int bind (int index, const std::string &param)
 bind a string parameter
 
int bind (int index, const std::vector< std::byte > &param)
 bind a bytestream
 
template<class T >
int bind (int index, const std::optional< T > &param)
 bind an optional: if it doesn't have a value we bind NULL
 

Private Attributes

sqlite3_stmt * m_stmt
 statement on which to work on
 

Detailed Description

Bind the given parameter to the sqlite statement.

This functor object only serves the purpose to bind the values of the given parameters to a sqlite statement. So given a tuple of parameters it can be used to bind all the values in the tuple to the statement with the correct type.

Definition at line 110 of file sqlite.h.

Constructor & Destructor Documentation

◆ ParameterBinder()

ParameterBinder ( sqlite3_stmt *  statement)
inlineexplicit

Create a new object for the given statement.

Definition at line 113 of file sqlite.h.

113: m_stmt(statement) {}
sqlite3_stmt * m_stmt
statement on which to work on
Definition: sqlite.h:146

Member Function Documentation

◆ bind() [1/6]

int bind ( int  index,
const std::optional< T > &  param 
)
inlineprivate

bind an optional: if it doesn't have a value we bind NULL

Definition at line 141 of file sqlite.h.

142 {
143 if (param.has_value()) return bind(*param);
144 return sqlite3_bind_null(m_stmt, index);
145 }
int bind(int index, int param)
bind an integer parameter
Definition: sqlite.h:124

◆ bind() [2/6]

int bind ( int  index,
const std::string &  param 
)
inlineprivate

bind a string parameter

Definition at line 130 of file sqlite.h.

131 {
132 return sqlite3_bind_text(m_stmt, index, param.data(), param.size(), SQLITE_TRANSIENT);
133 }

◆ bind() [3/6]

int bind ( int  index,
const std::vector< std::byte > &  param 
)
inlineprivate

bind a bytestream

Definition at line 135 of file sqlite.h.

136 {
137 return sqlite3_bind_blob(m_stmt, index, param.data(), param.size(), SQLITE_TRANSIENT);
138 }

◆ bind() [4/6]

int bind ( int  index,
double  param 
)
inlineprivate

bind a double parameter

Definition at line 128 of file sqlite.h.

128{ return sqlite3_bind_double(m_stmt, index, param);}

◆ bind() [5/6]

int bind ( int  index,
int  param 
)
inlineprivate

bind an integer parameter

Definition at line 124 of file sqlite.h.

124{ return sqlite3_bind_int(m_stmt, index, param);}

◆ bind() [6/6]

int bind ( int  index,
int64_t  param 
)
inlineprivate

bind a 64bit integer parameter

Definition at line 126 of file sqlite.h.

126{ return sqlite3_bind_int64(m_stmt, index, param); }

◆ operator()()

void operator() ( int  index,
T &&  param 
)
inline

Bind the parameter with the given index to the statement.

Definition at line 117 of file sqlite.h.

118 {
119 // For some reason bind parameters start at one ...
120 checkSQLiteError(bind(index + 1, std::forward<T>(param)));
121 }

Member Data Documentation

◆ m_stmt

sqlite3_stmt* m_stmt
private

statement on which to work on

Definition at line 146 of file sqlite.h.


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