Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.

Statement

Nicuvëo edited this page Mar 29, 2014 · 4 revisions

Statements represent a query, and the different states that are involved during the use of said query.

--

Constructors

Name Description
Statement() Creates an empty statement.
Statement(Database db, const char* query) Prepares a query against the given database.

--

Accessors

Name Description
bool busy() const Tells whether this statement has started to iterate.
bool ready() const Tells whether this statement is ready to iterate (!busy).
bool empty() const Checks whether this statement is empty.
int current_row_index() const Returns the current row index (-1 if not busy).
Row& current_row() const Returns the current row (empty if not busy).
int columns_number() const Returns the number of columns in the result.
const std::string& column_name(int column) const Returns the nth column name.
const std::vector<std::string>& columns_names() const Returns all column names.
Database database() const Returns the underlying database.
sqlite3_stmt* raw_data() const Returns the underlying raw sqlite3_stmt*.

--

Parameter binding

Name Description
Proxy operator[](const ParameterKey& k) Returns a Proxy to the parameter.
Proxy operator[](const ParameterName& n) Returns a Proxy to the parameter.
Proxy operator[](const ParameterIndex& p) Returns a Proxy to the parameter.
friend Statement& operator<<(Statement& s, const Parameter& p) Binds the given parameter.
friend Statement& operator<<(Statement& s, const Parameters& ps) Binds the given parameters.
Statement& bind(const Parameter& p) Binds the given parameter.
Statement& bind(const Parameters& ps) Binds the given parameters.
Statement& bind(const ParameterKey& k, const Value& v) Binds the given parameter.
Statement& bind(const ParameterName& n, const Value& v) Binds the given parameter.
Statement& bind(const ParameterIndex& i, const Value& v) Binds the given parameter.

Notes

  • Proxy are proxy objects that override the = operator, allowing you to write statement["pname"] = parameter;.

--

Execution

Name Description
Rows exec() Execute a query -> rows
Rows exec(const Parameters& params) Execute a query -> rows
void exec(const RowCallback& callback) Execute a query, callback on each row
void exec(const RowCallback& callback, const Parameters& params) Execute a query, callback on each row
RowRange result() Execute a query -> row range.
RowRange result(const Parameters& params) Execute a query -> row range.
bool step() Steps once; returns false if end reached.
void reset() Stops the current execution.

Notes:

  • Rows store the whole query result in memory, while RowRange allows you to iterate on the results one database row at a time.
  • Use the provided saw_foreach macro to iterate on a RowRange:
saw_foreach (const Row& r, db.result("select * from clients"))
{
  // do something with r
}

Clone this wiki locally