This class represents a prepared (or ordinary) statement that can be executed. More...
#include <cppdb/frontend.h>
Public Member Functions | |
statement () | |
~statement () | |
statement (statement const &) | |
statement const & | operator= (statement const &) |
void | reset () |
void | clear () |
bool | empty () const |
statement & | bind (int v) |
statement & | bind (unsigned v) |
statement & | bind (long v) |
statement & | bind (unsigned long v) |
statement & | bind (long long v) |
statement & | bind (unsigned long long v) |
statement & | bind (double v) |
statement & | bind (long double v) |
statement & | bind (std::string const &v) |
statement & | bind (char const *s) |
statement & | bind (char const *b, char const *e) |
statement & | bind (std::tm const &v) |
statement & | bind (std::istream &v) |
statement & | bind_null () |
void | bind (int col, int v) |
void | bind (int col, unsigned v) |
void | bind (int col, long v) |
void | bind (int col, unsigned long v) |
void | bind (int col, long long v) |
void | bind (int col, unsigned long long v) |
void | bind (int col, double v) |
void | bind (int col, long double v) |
void | bind (int col, std::string const &v) |
void | bind (int col, char const *s) |
void | bind (int col, char const *b, char const *e) |
void | bind (int col, std::tm const &v) |
void | bind (int col, std::istream &v) |
void | bind_null (int col) |
long long | last_insert_id () |
long long | sequence_last (std::string const &seq) |
unsigned long long | affected () |
result | row () |
result | query () |
operator result () | |
void | exec () |
statement & | operator<< (std::string const &v) |
statement & | operator<< (char const *s) |
statement & | operator<< (std::tm const &v) |
statement & | operator<< (std::istream &v) |
statement & | operator<< (void(*manipulator)(statement &st)) |
result | operator<< (result(*manipulator)(statement &st)) |
template<typename T > | |
statement & | operator<< (tags::use_tag< T > const &val) |
template<typename T > | |
statement & | operator<< (T v) |
Friends | |
class | session |
This class represents a prepared (or ordinary) statement that can be executed.
This object is usually created via session::prepare() function.
Default constructor, provided for convenience, access to any member function of empty statement will cause an exception being thrown.
Destructor, it releases prepared statement and if the statements cache is enabled it returns it into the cache.
Note: if result object created by this statement is alive, the underlying backned::statement would be on hold until result object is destroyed and only then the statement would be put back into cache.
cppdb::statement::statement | ( | statement const & | ) |
Copy statement.
Please note it copies only the reference to underlying statement object, so copies of same statement represent same object and it is strongly not recommended to access the underlying backend::statement by two different statement objects.
unsigned long long cppdb::statement::affected | ( | ) |
Get the number of affected rows by the last statement,
If the statement is actually query, the behavior is undefined and may vary between backends.
statement& cppdb::statement::bind | ( | int | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | unsigned | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | long | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | unsigned long | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | long long | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | unsigned long long | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | double | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | long double | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | std::string const & | v | ) |
Bind a string value v to the next placeholder marked with '?' marker in the query.
Note: the reference to the string MUST remain valid until the statement is queried or executed!
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | char const * | s | ) |
Bind a null terminated string value s to the next placeholder marked with '?' marker in the query.
Note: the reference to the string MUST remain valid until the statement is queried or executed!
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | char const * | b, |
char const * | e | ||
) |
Bind a string value in range [b, e ) to the next placeholder marked with '?' marker in the query.
Note: the reference to the string MUST remain valid until the statement is queried or executed!
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | std::tm const & | v | ) |
Bind a value v to the next placeholder (starting from the first) marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
statement& cppdb::statement::bind | ( | std::istream & | v | ) |
Bind a BLOB value v to the next placeholder marked with '?' marker in the query.
Note: the reference to the stream MUST remain valid until the statement is queried or executed!
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
int | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
unsigned | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
long | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
unsigned long | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
long long | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
unsigned long long | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
double | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
long double | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
std::string const & | v | ||
) |
Bind a string value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
Note: the reference to the string MUST remain valid until the statement is queried or executed!
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
char const * | s | ||
) |
Bind a null terminated string value s to the placeholder number col (starting from 1) marked with '?' marker in the query.
Note: the reference to the string MUST remain valid until the statement is queried or executed!
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
char const * | b, | ||
char const * | e | ||
) |
Bind a string value in range [b, e ) to the placeholder number col (starting from 1) marked with '?' marker in the query.
Note: the reference to the string MUST remain valid until the statement is queried or executed!
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
std::tm const & | v | ||
) |
Bind a value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind | ( | int | col, |
std::istream & | v | ||
) |
Bind a BLOB value v to the placeholder number col (starting from 1) marked with '?' marker in the query.
Note: the reference to the stream MUST remain valid until the statement is queried or executed!
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
Bind a NULL value to the next placeholder marked with '?' marker in the query.
If number of calls is higher then the number placeholders is the statement it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::bind_null | ( | int | col | ) |
Bind a NULL value to the placeholder number col (starting from 1) marked with '?' marker in the query.
If cols is invalid (less then 1 or higher then the number of the placeholders is the statement) it may throw invalid_placeholder exception.
If placeholder was not binded the behavior is undefined and may vary between different backends.
void cppdb::statement::clear | ( | ) |
Clear the statement, removes it, any access to statement object would throw an exception till it would be assigned once again
bool cppdb::statement::empty | ( | ) | const |
Check if the statement is empty, it is empty when created with default constructor or when cleared with clear() member function.
void cppdb::statement::exec | ( | ) |
Execute a statement, of the statement is actually SELECT like operator, it throws cppdb_error exception, however the behavior may vary between backends that may ignore this error.
long long cppdb::statement::last_insert_id | ( | ) |
Get last insert id from the last executed statement, note, it is the same as sequence_last("").
Some backends requires explicit sequence name so you should use sequence_last("sequence_name") in such case.
If the statement is actually query, the behavior is undefined and may vary between backends.
statement& cppdb::statement::operator<< | ( | std::string const & | v | ) |
Same as bind(v);
statement& cppdb::statement::operator<< | ( | char const * | s | ) |
Same as bind(s);
statement& cppdb::statement::operator<< | ( | std::tm const & | v | ) |
Same as bind(v);
statement& cppdb::statement::operator<< | ( | std::istream & | v | ) |
Same as bind(v);
Apply manipulator on the statement, same as manipulator(*this).
Apply manipulator on the statement, same as manipulator(*this).
statement& cppdb::statement::operator<< | ( | tags::use_tag< T > const & | val | ) | [inline] |
Used together with use() function.
The call st<<use(x,tag) is same as
(tag == null_value) ? st.bind_null() : st.bind(x)
statement& cppdb::statement::operator<< | ( | T | v | ) | [inline] |
Same as bind(v);
Assign a statement.
Please note it copies only the reference to underlying statement object, so copies of same statement represent same object and it is strongly not recommended to access the underlying backend::statement by two different statement objects.
Fetch a result of the query, if the statement is not query statement (like SELECT) it would likely throw an exception, however the behavior may vary between backends that may ignore this error.
void cppdb::statement::reset | ( | ) |
Reset the statement - remove all bindings and return it into initial state so query() or exec() functions can be called once again.
You must use it if you use the same statement multiple times.
Note, it is different from clear() where the statement is fully released and access to it would throw an exception
Fetch a single row from the query. Unlike query(), you should not call result::next() function as it is already called. You may check if the data was fetched using result::empty() function.
If the result set consists of more then one row it throws multiple_rows_query exception, however some backends may ignore this.
If the statement is not query statement (like SELECT) it would likely throw an exception, however the behavior may vary between backends that may ignore this error.
long long cppdb::statement::sequence_last | ( | std::string const & | seq | ) |
Get last created sequence value from the last executed statement.
If the backend does not support named sequences but rather supports "auto increment" columns (like MySQL, Sqlite3), the seq parameter is ignored.
If the statement is actually query, the behavior is undefined and may vary between backends.