SQLite Containers
Loading...
Searching...
No Matches
sqlite_containers::SqliteStmt Class Reference

Class for managing SQLite prepared statements. More...

#include <SqliteStmt.hpp>

Public Member Functions

 SqliteStmt ()=default
 Default constructor.
 
 SqliteStmt (sqlite3 *sqlite_db, const char *query)
 Constructs a SqliteStmt and prepares the statement.
 
 SqliteStmt (sqlite3 *sqlite_db, const std::string &query)
 Constructs a SqliteStmt and prepares the statement.
 
 ~SqliteStmt ()
 Destructor.
 
void init (sqlite3 *sqlite_db, const char *query)
 Initializes the statement.
 
void init (sqlite3 *sqlite_db, const std::string &query)
 Initializes the statement.
 
sqlite3_stmt * get_stmt () noexcept
 Gets the prepared SQLite statement.
 
void reset ()
 Resets the prepared statement.
 
void clear_bindings ()
 Clears all bindings on the prepared statement.
 
void execute (sqlite3 *sqlite_db)
 Executes the prepared statement.
 
void execute ()
 Executes the prepared statement.
 
int step ()
 
template<typename T >
extract_column (const int &index, typename std::enable_if< std::is_integral< T >::value >::type *=0)
 Extracts a value from a SQLite statement column.
 
template<typename T >
extract_column (const int &index, typename std::enable_if< std::is_floating_point< T >::value >::type *=0)
 
template<typename T >
extract_column (const int &index, typename std::enable_if< std::is_same< T, std::string >::value >::type *=0)
 
template<typename T >
extract_column (const int &index, typename std::enable_if< std::is_same< T, std::vector< char > >::value >::type *=0)
 
template<typename T >
extract_column (const int &index, typename std::enable_if< std::is_same< T, std::vector< uint8_t > >::value >::type *=0)
 
template<typename T >
extract_column (const int &index, typename std::enable_if< !std::is_integral< T >::value &&!std::is_floating_point< T >::value &&!std::is_same< T, std::string >::value &&!std::is_same< T, std::vector< char > >::value &&!std::is_same< T, std::vector< uint8_t > >::value &&std::is_trivially_copyable< T >::value >::type *=0)
 
template<typename T >
bool bind_value (const int &index, const T &value, typename std::enable_if< std::is_integral< T >::value >::type *=0)
 Binds a value to a SQLite statement.
 
template<typename T >
bool bind_value (const int &index, const T &value, typename std::enable_if< std::is_floating_point< T >::value >::type *=0)
 
template<typename T >
bool bind_value (const int &index, const T &value, typename std::enable_if< std::is_same< T, std::string >::value >::type *=0)
 
template<typename T >
bool bind_value (const int &index, const T &value, typename std::enable_if< std::is_same< T, std::vector< char > >::value >::type *=0)
 
template<typename T >
bool bind_value (const int &index, const T &value, typename std::enable_if< std::is_same< T, std::vector< uint8_t > >::value >::type *=0)
 
template<typename T >
bool bind_value (const int &index, const T &value, typename std::enable_if< !std::is_integral< T >::value &&!std::is_floating_point< T >::value &&!std::is_same< T, std::string >::value &&!std::is_same< T, std::vector< char > >::value &&!std::is_same< T, std::vector< uint8_t > >::value &&std::is_trivially_copyable< T >::value >::type *=0)
 

Private Attributes

sqlite3_stmt * m_stmt = nullptr
 Pointer to the prepared SQLite statement.
 

Detailed Description

Class for managing SQLite prepared statements.

Definition at line 11 of file SqliteStmt.hpp.

Constructor & Destructor Documentation

◆ SqliteStmt() [1/3]

sqlite_containers::SqliteStmt::SqliteStmt ( )
default

Default constructor.

◆ SqliteStmt() [2/3]

sqlite_containers::SqliteStmt::SqliteStmt ( sqlite3 * sqlite_db,
const char * query )
inline

Constructs a SqliteStmt and prepares the statement.

Parameters
sqlite_dbPointer to the SQLite database.
querySQL query to prepare.
Exceptions
sqlite_exceptionif the query preparation fails.

Definition at line 21 of file SqliteStmt.hpp.

◆ SqliteStmt() [3/3]

sqlite_containers::SqliteStmt::SqliteStmt ( sqlite3 * sqlite_db,
const std::string & query )
inline

Constructs a SqliteStmt and prepares the statement.

Parameters
sqlite_dbPointer to the SQLite database.
querySQL query to prepare.
Exceptions
sqlite_exceptionif the query preparation fails.

Definition at line 29 of file SqliteStmt.hpp.

◆ ~SqliteStmt()

sqlite_containers::SqliteStmt::~SqliteStmt ( )
inline

Destructor.

Definition at line 34 of file SqliteStmt.hpp.

Member Function Documentation

◆ bind_value() [1/6]

template<typename T >
bool sqlite_containers::SqliteStmt::bind_value ( const int & index,
const T & value,
typename std::enable_if< !std::is_integral< T >::value &&!std::is_floating_point< T >::value &&!std::is_same< T, std::string >::value &&!std::is_same< T, std::vector< char > >::value &&!std::is_same< T, std::vector< uint8_t > >::value &&std::is_trivially_copyable< T >::value >::type * = 0 )
inline

Definition at line 207 of file SqliteStmt.hpp.

◆ bind_value() [2/6]

template<typename T >
bool sqlite_containers::SqliteStmt::bind_value ( const int & index,
const T & value,
typename std::enable_if< std::is_floating_point< T >::value >::type * = 0 )
inline

Definition at line 183 of file SqliteStmt.hpp.

◆ bind_value() [3/6]

template<typename T >
bool sqlite_containers::SqliteStmt::bind_value ( const int & index,
const T & value,
typename std::enable_if< std::is_integral< T >::value >::type * = 0 )
inline

Binds a value to a SQLite statement.

Parameters
indexIndex of the parameter to bind.
valueThe value to bind.
Returns
True if the value was successfully bound, otherwise false.

Definition at line 177 of file SqliteStmt.hpp.

◆ bind_value() [4/6]

template<typename T >
bool sqlite_containers::SqliteStmt::bind_value ( const int & index,
const T & value,
typename std::enable_if< std::is_same< T, std::string >::value >::type * = 0 )
inline

Definition at line 189 of file SqliteStmt.hpp.

◆ bind_value() [5/6]

template<typename T >
bool sqlite_containers::SqliteStmt::bind_value ( const int & index,
const T & value,
typename std::enable_if< std::is_same< T, std::vector< char > >::value >::type * = 0 )
inline

Definition at line 195 of file SqliteStmt.hpp.

◆ bind_value() [6/6]

template<typename T >
bool sqlite_containers::SqliteStmt::bind_value ( const int & index,
const T & value,
typename std::enable_if< std::is_same< T, std::vector< uint8_t > >::value >::type * = 0 )
inline

Definition at line 201 of file SqliteStmt.hpp.

◆ clear_bindings()

void sqlite_containers::SqliteStmt::clear_bindings ( )
inline

Clears all bindings on the prepared statement.

Exceptions
sqlite_exceptionif the clear bindings operation fails.

Definition at line 85 of file SqliteStmt.hpp.

◆ execute() [1/2]

void sqlite_containers::SqliteStmt::execute ( )
inline

Executes the prepared statement.

Exceptions
sqlite_exceptionif the execution fails.

Definition at line 100 of file SqliteStmt.hpp.

◆ execute() [2/2]

void sqlite_containers::SqliteStmt::execute ( sqlite3 * sqlite_db)
inline

Executes the prepared statement.

Parameters
sqlite_dbPointer to the SQLite database.
Exceptions
sqlite_exceptionif the execution fails.

Definition at line 94 of file SqliteStmt.hpp.

◆ extract_column() [1/6]

template<typename T >
T sqlite_containers::SqliteStmt::extract_column ( const int & index,
typename std::enable_if< !std::is_integral< T >::value &&!std::is_floating_point< T >::value &&!std::is_same< T, std::string >::value &&!std::is_same< T, std::vector< char > >::value &&!std::is_same< T, std::vector< uint8_t > >::value &&std::is_trivially_copyable< T >::value >::type * = 0 )
inline

Definition at line 152 of file SqliteStmt.hpp.

◆ extract_column() [2/6]

template<typename T >
T sqlite_containers::SqliteStmt::extract_column ( const int & index,
typename std::enable_if< std::is_floating_point< T >::value >::type * = 0 )
inline

Definition at line 120 of file SqliteStmt.hpp.

◆ extract_column() [3/6]

template<typename T >
T sqlite_containers::SqliteStmt::extract_column ( const int & index,
typename std::enable_if< std::is_integral< T >::value >::type * = 0 )
inline

Extracts a value from a SQLite statement column.

Parameters
indexIndex of the column to extract.
Returns
The extracted value.

Definition at line 114 of file SqliteStmt.hpp.

◆ extract_column() [4/6]

template<typename T >
T sqlite_containers::SqliteStmt::extract_column ( const int & index,
typename std::enable_if< std::is_same< T, std::string >::value >::type * = 0 )
inline

Definition at line 126 of file SqliteStmt.hpp.

◆ extract_column() [5/6]

template<typename T >
T sqlite_containers::SqliteStmt::extract_column ( const int & index,
typename std::enable_if< std::is_same< T, std::vector< char > >::value >::type * = 0 )
inline

Definition at line 136 of file SqliteStmt.hpp.

◆ extract_column() [6/6]

template<typename T >
T sqlite_containers::SqliteStmt::extract_column ( const int & index,
typename std::enable_if< std::is_same< T, std::vector< uint8_t > >::value >::type * = 0 )
inline

Definition at line 144 of file SqliteStmt.hpp.

◆ get_stmt()

sqlite3_stmt * sqlite_containers::SqliteStmt::get_stmt ( )
inlinenoexcept

Gets the prepared SQLite statement.

Returns
Pointer to the prepared SQLite statement.

Definition at line 71 of file SqliteStmt.hpp.

◆ init() [1/2]

void sqlite_containers::SqliteStmt::init ( sqlite3 * sqlite_db,
const char * query )
inline

Initializes the statement.

Parameters
sqlite_dbPointer to the SQLite database.
querySQL query to prepare.
Exceptions
sqlite_exceptionif the query preparation fails.

Definition at line 44 of file SqliteStmt.hpp.

◆ init() [2/2]

void sqlite_containers::SqliteStmt::init ( sqlite3 * sqlite_db,
const std::string & query )
inline

Initializes the statement.

Parameters
sqlite_dbPointer to the SQLite database.
querySQL query to prepare.
Exceptions
sqlite_exceptionif the query preparation fails.

Definition at line 65 of file SqliteStmt.hpp.

◆ reset()

void sqlite_containers::SqliteStmt::reset ( )
inline

Resets the prepared statement.

Exceptions
sqlite_exceptionif the reset operation fails.

Definition at line 77 of file SqliteStmt.hpp.

◆ step()

int sqlite_containers::SqliteStmt::step ( )
inline

brief Advances the prepared statement to the next result row or completion. return Result code: SQLITE_ROW for a new row, SQLITE_DONE for completion, or an error code.

Definition at line 106 of file SqliteStmt.hpp.

Member Data Documentation

◆ m_stmt

sqlite3_stmt* sqlite_containers::SqliteStmt::m_stmt = nullptr
private

Pointer to the prepared SQLite statement.

Definition at line 220 of file SqliteStmt.hpp.


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