Main  /  Edit version 2  /  Edit version 3  /   /  Users Area

Difference "dbixx::row" ver. 2 versus ver. 3

Content:

This class is used for fetching data from single row. It receives the result from [`dbixx::session`](/wikipp/en/page/ref_dbixx_session) or [`dbixx::result`](/wikipp/en/page/ref_dbixx_result).
- [General Functions](#gen)
- [Retrieving information about fields](#finfo)
- [Retrieving actual data](#data)
- [Automatic Casting](#cast)
## <span id="gen"></span>General Functions
bool isempty();
dbi_result get_dbi_result()
`isempty()` checks if the output set of the query was empty.
dbixx::row r
sql<<"SELECT id FROM users WHERE name='nobody'",r;
if(!r.isempty()) { // there is nobody in list!!!
`get_dbi_result()` returns underlying `dbi_result` that
allows accessing libdbi features that are not available
from DbiXX Library
## <span id="finfo"></span>Retrieving information about fields
unsigned int cols();
bool isnull(int inx);
bool isnull(std::string const &id);
bool operator[](int ind);
bool operator[](std::string const & id) ;
Function `cols()` returns number of columns in the row. `isnull()` returns if specific filed is null, using it's column number (starting from 1) or column name;
`bool operator[]` is just syntactic sugar for `isnull()`.
For example:
row r;
sql<<"SELECT password "
"FROM users WHERE username=?",name,r;
if(!r.isempty() && r.isnull("password")) {
// login without password
## <span id="data"></id>Retrieving actual data
## <span id="data"></span>Retrieving actual data
The operation for retrieving the data are following:
bool fetch(int idx,int &value);
bool fetch(int idx,unsigned &value);
bool fetch(int idx,long long &value);
bool fetch(int idx,unsigned long long &value);
bool fetch(int idx,double &value);
bool fetch(int idx,std::string &value);
bool fetch(int idx,std::tm &value);
template<typename T>
row &operator>>(T &v);
Function `fetch`, retrieves the value from column `idx` into value. And returns `true` if the value is **not** null.
Operator `>>` allows fetch data from all columns sequentially starting from column number 1.
For example:
dbixx::row r;
sql<<"SELECT name,age,birthday "
"FROM person WHERE id=?",id;
if(sql.single(r)) {
int age;
string name;
std::tm birth;
r >> name >> age >>birth;
// Do something
}
## <span id="cast"></span>Automatic Casting
If data type does not mutch, DbiXX tries to cast data
to appropriate type, thus you can retrieve double with
integer or even string. This is done mostly for
"typeless" backends like sqlite3 where strict casting
may cause unexpected errors.
If casting fails, `dbixx::dbixx_error` is thrown.

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0