tntdb::RowReader Class Reference

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

`#include <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>
RowReader & | get (T &ret)
| Reads the current column value and increments the field counter.
template<typename T>
RowReader & | get (T &ret, bool &nullInd)
| Reads the current column value and a null indicator and increments the field counter.
RowReader & | get (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 Row & | currentRow () 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
// ...
}
tntdb::Statement::const_iterator
This class represents a database-cursor.
Definition statement_iterator.h:46
tntdb::Statement
This class represents an SQL statement.
Definition statement.h:73
tntdb::Statement::end
const_iterator end() const
Get an end iterator.
Definition statement.h:46
tntdb::Statement::begin
const_iterator begin(unsigned fetchsize=100) const
Create a database cursor and fetch the first row of the query result.

## Constructor & Destructor Documentation

## RowReader()

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

inline explicit

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

## Member Function Documentation

## currentCol()

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

inline

returns the current column number.

## currentRow()

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

inline

returns the underlying row.

## get() [1/3]

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.

## get() [2/3]

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.

## get() [3/3]

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

inline

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

## isNull()

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

inline

Returns true, if the current value is null.

## operator++() [1/2]

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

inline

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

## operator++() [2/2]

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

inline

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

## operator--() [1/2]

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

inline

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

## operator--() [2/2]

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

inline

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

## rewind()

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:

- tntdb/bits/rowreader.h