Belle II Software development
ColumnFiller Class Reference

Struct to fill the different columns in a sqlite result row into a std::tuple. More...

#include <sqlite.h>

Public Member Functions

 ColumnFiller (sqlite3_stmt *statement)
 Create a new instance for the given statement.
 
void operator() (int index, int &col)
 Fill integer column.
 
void operator() (int index, int64_t &col)
 Fill 64bit integer column.
 
void operator() (int index, double &col)
 Fill double column.
 
void operator() (int index, std::string &col)
 Fill string column.
 
void operator() (int index, std::vector< std::byte > &col)
 Fill blob column.
 
template<class T >
void operator() (int index, std::optional< T > &col)
 Fill an possibly null column in an optional.
 

Private Attributes

sqlite3_stmt * m_stmt
 statement on which to work on
 

Detailed Description

Struct to fill the different columns in a sqlite result row into a std::tuple.

So given a sqlite statement with result values and a std::tuple to adopt all these values this class can be used to extract the values of the row into the given references with the correct types.

Definition at line 63 of file sqlite.h.

Constructor & Destructor Documentation

◆ ColumnFiller()

ColumnFiller ( sqlite3_stmt *  statement)
inlineexplicit

Create a new instance for the given statement.

Definition at line 66 of file sqlite.h.

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

Member Function Documentation

◆ operator()() [1/6]

void operator() ( int  index,
double &  col 
)
inline

Fill double column.

Definition at line 72 of file sqlite.h.

72{ col = sqlite3_column_double(m_stmt, index); }

◆ operator()() [2/6]

void operator() ( int  index,
int &  col 
)
inline

Fill integer column.

Definition at line 68 of file sqlite.h.

68{ col = sqlite3_column_int(m_stmt, index); }

◆ operator()() [3/6]

void operator() ( int  index,
int64_t &  col 
)
inline

Fill 64bit integer column.

Definition at line 70 of file sqlite.h.

70{ col = sqlite3_column_int(m_stmt, index); }

◆ operator()() [4/6]

void operator() ( int  index,
std::optional< T > &  col 
)
inline

Fill an possibly null column in an optional.

Definition at line 92 of file sqlite.h.

93 {
94 if (sqlite3_column_type(m_stmt, index) != SQLITE_NULL) {
95 col.emplace();
96 (*this)(index, *col);
97 }
98 }

◆ operator()() [5/6]

void operator() ( int  index,
std::string &  col 
)
inline

Fill string column.

Definition at line 74 of file sqlite.h.

75 {
76 // ptr is owned by sqlite, no need to free but we need to copy
77 if (auto ptr = reinterpret_cast<const char*>(sqlite3_column_text(m_stmt, index)); ptr != nullptr) {
78 col = ptr;
79 }
80 }

◆ operator()() [6/6]

void operator() ( int  index,
std::vector< std::byte > &  col 
)
inline

Fill blob column.

Definition at line 82 of file sqlite.h.

83 {
84 // ptr is owned by sqlite, no need to free but we need to copy
85 if (auto ptr = reinterpret_cast<const std::byte*>(sqlite3_column_blob(m_stmt, index)); ptr != nullptr) {
86 size_t bytes = sqlite3_column_bytes(m_stmt, index);
87 col = std::vector<std::byte>(ptr, ptr + bytes);
88 }
89 }

Member Data Documentation

◆ m_stmt

sqlite3_stmt* m_stmt
private

statement on which to work on

Definition at line 100 of file sqlite.h.


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