liarsdice::database::PreparedStatement class

RAII wrapper for SQLite prepared statements.

Public types

using ValueType = std::variant<std::monostate, int, int64_t, double, std::string, std::vector<uint8_t>>

Constructors, destructors, conversion operators

PreparedStatement(sqlite3_stmt* stmt, const std::string& sql)
Constructor.
operator bool() const explicit
Check if statement is valid.

Public functions

auto bind(int index, const ValueType& value) -> bool
Bind parameter by index (1-based)
auto bind(const std::string& name, const ValueType& value) -> bool
Bind parameter by name.
auto reset() -> bool
Reset statement for reuse.
auto clear_bindings() -> bool
Clear all bindings.
auto step() -> int
Execute a step.
auto column_count() const -> int
Get column count.
auto get_column(int index) const -> ValueType
Get column value by index.
auto get_column_name(int index) const -> std::string
Get column name.
auto sql() const -> const std::string&
Get the original SQL.
auto get() const -> sqlite3_stmt*
Get the underlying statement handle.

Function documentation

liarsdice::database::PreparedStatement::PreparedStatement(sqlite3_stmt* stmt, const std::string& sql)

Constructor.

Parameters
stmt SQLite statement (takes ownership)
sql Original SQL for reference

int liarsdice::database::PreparedStatement::step()

Execute a step.

Returns SQLITE_ROW, SQLITE_DONE, or error code