Library: Data
Package: DataCore
Header: Poco/Data/RecordSet.h
RecordSet provides access to data returned from a query. Data access indices (row and column) are 0-based, as usual in C++.
Recordset provides navigation methods to iterate through the recordset, retrieval methods to extract data, and methods to get metadata (type, etc.) about columns.
To work with a RecordSet, first create a Statement, execute it, and create the RecordSet from the Statement, as follows:
Statement select(session); select << "SELECT * FROM Person"; select.execute(); RecordSet rs(select);
The shorter way to do the above is following:
RecordSet rs(session, "SELECT * FROM Person"[, new SimpleRowFormatter]);
The third (optional) argument passed to the Recordset constructor is a RowFormatter implementation. The formatter is used in conjunction with << operator for recordset data formating.
The number of rows in the RecordSet can be limited by specifying a limit for the Statement.
Direct Base Classes: Statement
All Base Classes: Statement
Member Functions: begin, column, columnCount, columnLength, columnName, columnPrecision, columnType, copy, copyNames, copyValues, end, extractedRowCount, formatNames, formatValues, getTotalRowCount, isFiltered, isNull, moveFirst, moveLast, moveNext, movePrevious, nvl, operator =, operator [], row, rowCount, setRowFormatter, setTotalRowCount, totalRowCount, value
Inherited Functions: addBind, addBinding, addExtract, addExtraction, addExtractions, canModifyStorage, columnsExtracted, dataSetCount, done, execute, executeAsync, extractionCount, extractions, getRowFormatter, getStorage, hasMoreDataSets, impl, initialized, isAsync, isBulkExtraction, isNull, metaColumn, nextDataSet, operator <<, operator =, operator,, paused, previousDataSet, removeBind, reset, rowsExtracted, session, setAsync, setRowFormatter, setStorage, storage, subTotalRowCount, swap, toString, wait
typedef const RowIterator ConstIterator;
typedef RowIterator Iterator;
typedef std::map < std::size_t, Row * > RowMap;
RecordSet(
const RecordSet & other
);
Copy-creates the recordset.
explicit RecordSet(
const Statement & rStatement,
RowFormatter::Ptr pRowFormatter = 0
);
Creates the RecordSet.
explicit RecordSet(
Session & rSession,
const std::string & query,
RowFormatter::Ptr pRowFormatter = 0
);
Creates the RecordSet.
explicit RecordSet(
Session & rSession,
const std::string & query,
const RowFormatter & rowFormatter
);
Creates the RecordSet.
template < class RF > RecordSet(
Session & rSession,
const std::string & query,
const RF & rowFormatter
);
Creates the RecordSet.
~RecordSet();
Destroys the RecordSet.
ConstIterator & begin() const;
Returns the const row iterator.
Iterator begin();
Returns the row iterator.
template < class C > const Column < C > & column(
const std::string & name
) const;
Returns the reference to the first Column with the specified name.
template < class C > const Column < C > & column(
std::size_t pos
) const;
Returns the reference to column at specified position.
std::size_t columnCount() const;
Returns the number of columns in the recordset.
std::size_t columnLength(
std::size_t pos
) const;
Returns column maximum length for the column at specified position.
std::size_t columnLength(
const std::string & name
) const;
Returns column maximum length for the column with specified name.
const std::string & columnName(
std::size_t pos
) const;
Returns column name for the column at specified position.
std::size_t columnPrecision(
std::size_t pos
) const;
Returns column precision for the column at specified position. Valid for floating point fields only (zero for other data types).
std::size_t columnPrecision(
const std::string & name
) const;
Returns column precision for the column with specified name. Valid for floating point fields only (zero for other data types).
MetaColumn::ColumnDataType columnType(
std::size_t pos
) const;
Returns the type for the column at specified position.
MetaColumn::ColumnDataType columnType(
const std::string & name
) const;
Returns the type for the column with specified name.
std::ostream & copy(
std::ostream & os,
std::size_t offset = 0,
std::size_t length = RowIterator::POSITION_END
) const;
Copies the column names and values to the target output stream. Copied strings are formatted by the current RowFormatter.
std::ostream & copyNames(
std::ostream & os
) const;
Copies the column names to the target output stream. Copied string is formatted by the current RowFormatter.
std::ostream & copyValues(
std::ostream & os,
std::size_t offset = 0,
std::size_t length = RowIterator::POSITION_END
) const;
Copies the data values to the supplied output stream. The data set to be copied is starting at the specified offset from the recordset beginning. The number of rows to be copied is specified by length argument. An invalid combination of offset/length arguments shall cause RangeException to be thrown. Copied string is formatted by the current RowFormatter.
ConstIterator & end() const;
Returns the const row iterator.
Iterator end();
Returns the row iterator.
std::size_t extractedRowCount() const;
Returns the number of rows extracted during the last statement execution. The number of rows reported is independent of filtering.
void formatNames() const;
Formats names using the current RowFormatter.
void formatValues(
std::size_t offset,
std::size_t length
) const;
Formats values using the current RowFormatter. The data set to be formatted is starting at the specified offset from the recordset beginning. The number of rows to be copied is specified by length argument. An invalid combination of offset/length arguments shall cause RangeException to be thrown.
std::size_t getTotalRowCount() const;
Deprecated. This function is deprecated and should no longer be used.
Returns the total number of rows in the RecordSet. The number of rows reported is independent of filtering. If the total row count has not been set externally (either explicitly or implicitly through SQL), the value returned shall only be accurate if the statement limit is less or equal to the total row count.
bool isFiltered() const;
Returns true if recordset is filtered.
bool isNull(
const std::string & name
) const;
Returns true if column value of the current row is null.
bool moveFirst();
Moves the row cursor to the first row.
Returns true if there is at least one row in the RecordSet, false otherwise.
bool moveLast();
Moves the row cursor to the last row.
Returns true if there is at least one row in the RecordSet, false otherwise.
bool moveNext();
Moves the row cursor to the next row.
Returns true if the row is available, or false if the end of the record set has been reached and no more rows are available.
bool movePrevious();
Moves the row cursor to the previous row.
Returns true if the row is available, or false if there are no more rows available.
template < typename T > Poco::Dynamic::Var nvl(
const std::string & name,
const T & deflt = T ()
) const;
Returns the value in the named column of the current row if the value is not NULL, or deflt otherwise.
template < typename T > Poco::Dynamic::Var nvl(
std::size_t index,
const T & deflt = T ()
) const;
Returns the value in the given column of the current row if the value is not NULL, or deflt otherwise.
Statement & operator = (
const Statement & stmt
);
Assignment operator.
Poco::Dynamic::Var operator[] (
const std::string & name
);
Returns the value in the named column of the current row.
Poco::Dynamic::Var operator[] (
std::size_t index
);
Returns the value in the named column of the current row.
Row & row(
std::size_t pos
);
Returns reference to row at position pos. Rows are lazy-created and cached.
std::size_t rowCount() const;
Returns the number of rows in the RecordSet. The number of rows reported is dependent on filtering. Due to the need for filter conditions checking, this function may suffer significant performance penalty for large recordsets, so it should be used judiciously. Use totalRowCount() to obtain the total number of rows.
void setRowFormatter(
RowFormatter::Ptr pRowFormatter
);
Assigns the row formatter to the statement and all recordset rows.
void setTotalRowCount(
std::size_t totalRowCount
);
Explicitly sets the total row count.
void setTotalRowCount(
const std::string & sql
);
Implicitly sets the total row count. The supplied sql must return exactly one column and one row. The returned value must be an unsigned integer. The value is set as the total number of rows.
std::size_t totalRowCount() const;
Replaced with subTotalRowCount() and getTotalRowCount().
template < class T > const T & value(
std::size_t col,
std::size_t row,
bool useFilter = true
) const;
Returns the reference to data value at [col, row] location.
template < class T > const T & value(
const std::string & name,
std::size_t row,
bool useFilter = true
) const;
Returns the reference to data value at named column, row location.
Poco::Dynamic::Var value(
std::size_t col,
std::size_t row,
bool checkFiltering = true
) const;
Returns the data value at column, row location.
Poco::Dynamic::Var value(
const std::string & name,
std::size_t row,
bool checkFiltering = true
) const;
Returns the data value at named column, row location.
Poco::Dynamic::Var value(
const std::string & name
);
Returns the value in the named column of the current row.
Poco::Dynamic::Var value(
std::size_t index
);
Returns the value in the given column of the current row.
using Statement::isNull;
using Statement::subTotalRowCount;
static const std::size_t UNKNOWN_TOTAL_ROW_COUNT;