Sqlitepp
1.2.3
A thin sqlite C++ wrapper
|
Prepared statement obj - usually created by Connection::create_statement. More...
#include <sqlite.hpp>
Public Member Functions | |
Stmt (const std::string &sql, Connection &db) | |
Prepare a new statement for the given SQL. More... | |
Stmt (const Stmt &)=delete | |
Stmt & | operator= (const Stmt &)=delete |
Stmt (Stmt &&) | |
Stmt & | operator= (Stmt &&) |
std::string | bind_parameter_name (const int index) |
Get bind var name from index. More... | |
int | bind_parameter_index (const std::string &name) |
Get bind var index by name. More... | |
int | bind_parameter_count () |
Get number of bind parameters. More... | |
bool | step () |
Run the statement. More... | |
template<typename T > | |
T | get_col (const int column) |
Get SELECTed column. More... | |
void | reset () |
Reset the statement. More... | |
void | clear_bindings () |
Clear all bind vars to NULL. More... | |
bool | busy () |
Determine if the statment has been reset. More... | |
bool | readonly () |
Determine if the statment is read-only. More... | |
const sqlite3_stmt * | get_c_obj () const |
Get wrapped C sqlite3_stmt object (for use with the sqlite C API) More... | |
sqlite3_stmt * | get_c_obj () |
Get wrapped C sqlite3_stmt object (for use with the sqlite C API) More... | |
Bind functions | |
Functions for binding data to SQL statements | |
void | bind (const int index, const double val) |
Bind var by index. More... | |
void | bind (const int index, const int val) |
void | bind (const int index, const sqlite3_int64 val) |
void | bind (const int index, const std::string &val) |
void | bind (const int index, const char *val) |
void | bind_null (const int index) |
Bind null by index. More... | |
void | bind (const int index) |
Bind null by index. More... | |
void | bind (const std::string &name, const double val) |
Bind var by name. More... | |
void | bind (const std::string &name, const int val) |
void | bind (const std::string &name, const sqlite3_int64 val) |
void | bind (const std::string &name, const std::string &val) |
void | bind (const std::string &name, const char *val) |
void | bind_null (const std::string &name) |
Bind null by name. More... | |
void | bind (const std::string &name) |
Bind null by name. More... | |
Get columns | |
get_col() template specializations | |
template<> | |
double | get_col (const int column) |
Get SELECTed column. More... | |
template<> | |
int | get_col (const int column) |
Get SELECTed column. More... | |
template<> | |
sqlite3_int64 | get_col (const int column) |
Get SELECTed column. More... | |
template<> | |
std::string | get_col (const int column) |
Get SELECTed column. More... | |
template<> | |
const char * | get_col (const int column) |
Get SELECTed column. More... | |
Prepared statement obj - usually created by Connection::create_statement.
Data is bound to the statement with the bind() overloads, step() is called to execute the statement, and then get_col() can be used to retrieve rows from a SELECT statement.
When INSERTing or UPDATing multiple rows, call reset() to reuse the statement obj.
sqlite::Connection::Stmt::Stmt | ( | const std::string & | sql, |
Connection & | db | ||
) |
Prepare a new statement for the given SQL.
It is usually easier to use Connection::create_statement instead of this
[in] | sql | SQL code to prepare |
[in] | db | Database Connection to prepare statement for |
Logic_error | on error parsing SQL |
void sqlite::Connection::Stmt::bind | ( | const int | index, |
const double | val | ||
) |
Bind var by index.
[in] | index | Bind variable index |
[in] | val | Bind variable value |
Logic_error | on error binding |
void sqlite::Connection::Stmt::bind | ( | const int | index, |
const int | val | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void sqlite::Connection::Stmt::bind | ( | const int | index, |
const sqlite3_int64 | val | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void sqlite::Connection::Stmt::bind | ( | const int | index, |
const std::string & | val | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void sqlite::Connection::Stmt::bind | ( | const int | index, |
const char * | val | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void sqlite::Connection::Stmt::bind_null | ( | const int | index | ) |
Bind null by index.
[in] | index | Bind variable index |
Logic_error | on error binding |
void sqlite::Connection::Stmt::bind | ( | const int | index | ) |
Bind null by index.
[in] | index | Bind variable index |
Logic_error | on error binding |
void sqlite::Connection::Stmt::bind | ( | const std::string & | name, |
const double | val | ||
) |
Bind var by name.
[in] | name | Bind variable name |
[in] | val | Bind variable value |
Logic_error | on error binding |
void sqlite::Connection::Stmt::bind | ( | const std::string & | name, |
const int | val | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void sqlite::Connection::Stmt::bind | ( | const std::string & | name, |
const sqlite3_int64 | val | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void sqlite::Connection::Stmt::bind | ( | const std::string & | name, |
const std::string & | val | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void sqlite::Connection::Stmt::bind | ( | const std::string & | name, |
const char * | val | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void sqlite::Connection::Stmt::bind_null | ( | const std::string & | name | ) |
Bind null by name.
[in] | name | Bind variable name |
Logic_error | on error binding |
void sqlite::Connection::Stmt::bind | ( | const std::string & | name | ) |
Bind null by name.
[in] | name | Bind variable name |
Logic_error | on error binding |
std::string sqlite::Connection::Stmt::bind_parameter_name | ( | const int | index | ) |
Get bind var name from index.
[in] | index | Bind variable index |
Logic_error | on error finding name |
int sqlite::Connection::Stmt::bind_parameter_index | ( | const std::string & | name | ) |
Get bind var index by name.
[in] | name | Bind variable name |
Logic_error | on error finding index |
int sqlite::Connection::Stmt::bind_parameter_count | ( | ) |
bool sqlite::Connection::Stmt::step | ( | ) |
Run the statement.
true
on SELECT statements when more rows remain to be fetchedfalse
for UPDATE, DELETE, or database commands, or when no more rows can be SELECTED Logic_error | on error evaluating SQL |
T sqlite::Connection::Stmt::get_col | ( | const int | column | ) |
void sqlite::Connection::Stmt::reset | ( | ) |
Reset the statement.
Useful for inserting or updating multiple rows
Logic_error | on error resetting |
void sqlite::Connection::Stmt::clear_bindings | ( | ) |
Clear all bind vars to NULL.
bool sqlite::Connection::Stmt::busy | ( | ) |
Determine if the statment has been reset.
true
if the statement is busy (step has been called, but is not complete, nor reset) bool sqlite::Connection::Stmt::readonly | ( | ) |
Determine if the statment is read-only.
true
if the statement does not directly write to the DB const sqlite3_stmt * sqlite::Connection::Stmt::get_c_obj | ( | ) | const |
Get wrapped C sqlite3_stmt object (for use with the sqlite C API)
sqlite3_stmt * sqlite::Connection::Stmt::get_c_obj | ( | ) |
Get wrapped C sqlite3_stmt object (for use with the sqlite C API)
double sqlite::Connection::Stmt::get_col | ( | const int | column | ) |
int sqlite::Connection::Stmt::get_col | ( | const int | column | ) |
sqlite3_int64 sqlite::Connection::Stmt::get_col | ( | const int | column | ) |
std::string get_col< std::string > | ( | const int | column | ) |
const char* sqlite::Connection::Stmt::get_col | ( | const int | column | ) |