tntdb::RowReader Class Reference

A RowReader is a class which helps reading multiple columns from a row. More...

#include <tntdb/bits/rowreader.h>

Public Member Functions

 RowReader (const Row &row_, Row::size_type field_num_=0)
 instatiates a row reader with a row and a initial field counter
template<typename T >
RowReaderget (T &ret)
 Reads the current column value and increments the field counter.
template<typename T >
RowReaderget (T &ret, bool &nullInd)
 Reads the current column value and a null indicator and increments the field counter.
RowReaderget (tntdb::Value &v)
 Reads the current value into a tntdb::Value and increments the field counter.
bool isNull () const
 Returns true, if the current value is null.
void rewind (Row::size_type n_=0)
 Resets the field counter to the passed value.
const RowcurrentRow () const
 returns the underlying row.
Row::size_type currentCol () const
 returns the current column number.
Row::size_type operator++ ()
 increments the current column number and returns the incremented value (pre increment).
Row::size_type operator++ (int)
 increments the current column number and returns the previous value (post increment).
Row::size_type operator-- ()
 decrements the current column number and returns the decremented value (pre decrement).
Row::size_type operator-- (int)
 decrements the current column number and returns the previous value (post decrement).

Detailed Description

A RowReader is a class which helps reading multiple columns from a row.

This class helds a field number counter, which is incremented each time a value is fetched from the underlying row using one of the get methods. This class is normally instantiated implicitly using the tntdb::Row::reader method.

The get methods return a reference to the row reader to make chaining of calls easy.

Example:

tntdb::Statement s = conn.prepare("select col1, col2, col3 from table");
for (tntdb::Statement::const_iterator cur = s.begin(); cur != s.end(); ++cur)
{
int col1;
std::string col2;
long col3;
bool col3IsNotNull;
// note that a dereferenced cursor returns a tntdb::Row:
cur->reader().get(col1) // this fetches the first value and
// increments the field counter
.get(col2) // and the second
.get(col3, col3IsNotNull); // and this reads the 3rd column
// and a flag, if it is not null
// ...
// do whatever you need to do with the values here
// ...
}

Constructor & Destructor Documentation

tntdb::RowReader::RowReader ( const Row row_,
Row::size_type  field_num_ = 0 
)
inlineexplicit

instatiates a row reader with a row and a initial field counter

Member Function Documentation

Row::size_type tntdb::RowReader::currentCol ( ) const
inline

returns the current column number.

const Row& tntdb::RowReader::currentRow ( ) const
inline

returns the underlying row.

template<typename T >
RowReader& tntdb::RowReader::get ( T &  ret)
inline

Reads the current column value and increments the field counter.

If the value is null, the passed variable is not changed. There is no straight forward way to determine, whether the value was null. You should use the get method with the null indicator, if the value might be null or just initialize your value with a suitable default.

template<typename T >
RowReader& tntdb::RowReader::get ( T &  ret,
bool &  nullInd 
)
inline

Reads the current column value and a null indicator and increments the field counter.

If the value is null, the null indicator is set to false and the actual value of the passed variable is not changed.

RowReader& tntdb::RowReader::get ( tntdb::Value v)
inline

Reads the current value into a tntdb::Value and increments the field counter.

bool tntdb::RowReader::isNull ( ) const
inline

Returns true, if the current value is null.

Row::size_type tntdb::RowReader::operator++ ( )
inline

increments the current column number and returns the incremented value (pre increment).

Row::size_type tntdb::RowReader::operator++ ( int  )
inline

increments the current column number and returns the previous value (post increment).

Row::size_type tntdb::RowReader::operator-- ( )
inline

decrements the current column number and returns the decremented value (pre decrement).

Row::size_type tntdb::RowReader::operator-- ( int  )
inline

decrements the current column number and returns the previous value (post decrement).

void tntdb::RowReader::rewind ( Row::size_type  n_ = 0)
inline

Resets the field counter to the passed value.


The documentation for this class was generated from the following file: