This object represents query result. More...
#include <cppdb/frontend.h>
Public Member Functions | |
result () | |
~result () | |
result (result const &) | |
result const & | operator= (result const &) |
int | cols () |
bool | next () |
int | index (std::string const &n) |
int | find_column (std::string const &name) |
std::string | name (int col) |
bool | is_null (int col) |
bool | is_null (std::string const &n) |
void | clear () |
void | rewind_column () |
bool | empty () |
bool | fetch (int col, short &v) |
bool | fetch (int col, unsigned short &v) |
bool | fetch (int col, int &v) |
bool | fetch (int col, unsigned &v) |
bool | fetch (int col, long &v) |
bool | fetch (int col, unsigned long &v) |
bool | fetch (int col, long long &v) |
bool | fetch (int col, unsigned long long &v) |
bool | fetch (int col, float &v) |
bool | fetch (int col, double &v) |
bool | fetch (int col, long double &v) |
bool | fetch (int col, std::string &v) |
bool | fetch (int col, std::tm &v) |
bool | fetch (int col, std::ostream &v) |
bool | fetch (std::string const &n, short &v) |
bool | fetch (std::string const &n, unsigned short &v) |
bool | fetch (std::string const &n, int &v) |
bool | fetch (std::string const &n, unsigned &v) |
bool | fetch (std::string const &n, long &v) |
bool | fetch (std::string const &n, unsigned long &v) |
bool | fetch (std::string const &n, long long &v) |
bool | fetch (std::string const &n, unsigned long long &v) |
bool | fetch (std::string const &n, float &v) |
bool | fetch (std::string const &n, double &v) |
bool | fetch (std::string const &n, long double &v) |
bool | fetch (std::string const &n, std::string &v) |
bool | fetch (std::string const &n, std::tm &v) |
bool | fetch (std::string const &n, std::ostream &v) |
bool | fetch (short &v) |
bool | fetch (unsigned short &v) |
bool | fetch (int &v) |
bool | fetch (unsigned &v) |
bool | fetch (long &v) |
bool | fetch (unsigned long &v) |
bool | fetch (long long &v) |
bool | fetch (unsigned long long &v) |
bool | fetch (float &v) |
bool | fetch (double &v) |
bool | fetch (long double &v) |
bool | fetch (std::string &v) |
bool | fetch (std::tm &v) |
bool | fetch (std::ostream &v) |
template<typename T > | |
T | get (std::string const &name) |
template<typename T > | |
T | get (std::string const &name, T const &def) |
template<typename T > | |
T | get (int col) |
template<typename T > | |
T | get (int col, T const &def) |
template<typename T > | |
result & | operator>> (tags::into_tag< T > ref) |
template<typename T > | |
result & | operator>> (T &value) |
Friends | |
class | statement |
This object represents query result.
This object and it is generally created by statement::query() call, default constructor is provided for consistency, but access to any member function with exception of empty() would throw an exception.
Create an empty result, it is not useful except for having default constructor
Destroys the result, note, if the result of statement is not destroyed, it would not be returned to statements cache.
cppdb::result::result | ( | result const & | ) |
Copy result, note it only keeps the reference to actual object so copy is just copy of the reference
void cppdb::result::clear | ( | ) |
Clears the result, no further use of the result should be done until it is assigned again with a new statement result.
It is useful when you want to release all data and return the statement to cache
int cppdb::result::cols | ( | ) |
Return the number of columns in the result
bool cppdb::result::empty | ( | ) |
bool cppdb::result::fetch | ( | int | col, |
short & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
unsigned short & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
int & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
unsigned & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
long & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
unsigned long & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
long long & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
unsigned long long & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
float & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
double & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
long double & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
std::string & | v | ||
) |
Fetch a textual value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same, if possible it converts it into textual representation.
bool cppdb::result::fetch | ( | int | col, |
std::tm & | v | ||
) |
Fetch a value from column col (starting from 0) into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
bool cppdb::result::fetch | ( | int | col, |
std::ostream & | v | ||
) |
Fetch a binary large object value from column col (starting from 0) into a stream v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not blob, it may throw bad_value_cast()
bool cppdb::result::fetch | ( | std::string const & | n, |
short & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
unsigned short & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
int & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
unsigned & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
long & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
unsigned long & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
long long & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
unsigned long long & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
float & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
double & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
long double & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
std::string & | v | ||
) |
Fetch a textual value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same, if possible it converts it into textual representation. If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
std::tm & | v | ||
) |
Fetch a value from column named n into v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | std::string const & | n, |
std::ostream & | v | ||
) |
Fetch a binary large object value from column named name into a stream v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not blob, it may throw bad_value_cast(). If the n value is invalid throws invalid_column exception
bool cppdb::result::fetch | ( | short & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | unsigned short & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | int & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | unsigned & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | long & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | unsigned long & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | long long & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | unsigned long long & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | float & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | double & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | long double & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | std::string & | v | ) |
Fetch a textual value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same, if possible it converts it into textual representation.
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | std::tm & | v | ) |
Fetch a value from the next column in the row starting from the first one. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not same it tries to cast the data, if casting fails or the data is out of the type range, throws bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
bool cppdb::result::fetch | ( | std::ostream & | v | ) |
Fetch a blob value from the next column in the row starting from the first one into stream v. Returns false if the value in NULL and v is not updated, otherwise returns true.
If the data type is not blob, it may throw bad_value_cast().
If fetch was called more times then cols() it throws invalid_column exception, to use it once again from the beginning on the same row call rewind_column() member function. It is not required to call rewind_column() after calling next() as column index is reset automatically.
int cppdb::result::find_column | ( | std::string const & | name | ) |
Convert column name n to its index, returns -1 if the name is not valid.
T cppdb::result::get | ( | std::string const & | name | ) | [inline] |
Get a value of type T from column named name. If the column is null throws null_value_fetch(), if the column name is invalid throws invalid_column, if the column value cannot be converted to type T (see fetch functions) it throws bad_value_cast.
T cppdb::result::get | ( | std::string const & | name, |
T const & | def | ||
) | [inline] |
Get a value of type T from column named name. If the column is null returns def, if the column name is invalid throws invalid_column, if the column value cannot be converted to type T (see fetch functions) it throws bad_value_cast.
T cppdb::result::get | ( | int | col | ) | [inline] |
Get a value of type T from column col (starting from 0). If the column is null throws null_value_fetch(), if the column index is invalid throws invalid_column, if the column value cannot be converted to type T (see fetch functions) it throws bad_value_cast.
T cppdb::result::get | ( | int | col, |
T const & | def | ||
) | [inline] |
Get a value of type T from column col (starting from 0). If the column is null returns def, if the column index is invalid throws invalid_column, if the column value cannot be converted to type T (see fetch functions) it throws bad_value_cast.
int cppdb::result::index | ( | std::string const & | n | ) |
Convert column name n to its index, throws invalid_column if the name is not valid.
bool cppdb::result::is_null | ( | int | col | ) |
Return true if the column number col (starting from 0) has NULL value
bool cppdb::result::is_null | ( | std::string const & | n | ) |
Return true if the column named n has NULL value
std::string cppdb::result::name | ( | int | col | ) |
Convert column index to column name, throws invalid_column if col is not in range 0<= col < cols()
bool cppdb::result::next | ( | ) |
Move forward to next row, returns false if no more rows available.
Notes:
Assign result, note it only keeps the reference to actual object so assignment is just copy of the reference
result& cppdb::result::operator>> | ( | tags::into_tag< T > | ref | ) | [inline] |
Syntactic sugar, used together with into() function.
res << into(x,y) is same as
y = res.fetch(x) ? not_null_value : null_value
result& cppdb::result::operator>> | ( | T & | value | ) | [inline] |
Syntactic sugar, same as fetch(value)
void cppdb::result::rewind_column | ( | ) |
Reset current column index, so fetch without column index can be used once again