Poco::Data

class RecordSet

File Information

Library: Data
Package: DataCore
Header: Poco/Data/RecordSet.h

Description

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.

Inheritance

Direct Base Classes: Statement

All Base Classes: Statement

Member Summary

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 [], reset, row, rowCount, setRowFormatter, setTotalRowCount, totalRowCount, value

Inherited Functions: addBind, addBinding, addExtract, addExtraction, addExtractions, bind, 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

Types Aliases

ConstIterator

using ConstIterator = const RowIterator;

Iterator

using Iterator = RowIterator;

RowMap

using RowMap = std::map < std::size_t, Row * >;

Constructors

RecordSet

RecordSet(
    const RecordSet & other
);

Copy-creates the recordset.

RecordSet

RecordSet(
    RecordSet && other
) noexcept;

Move-creates the recordset.

RecordSet

explicit RecordSet(
    const Statement & rStatement,
    RowFormatter::Ptr pRowFormatter = 0
);

Creates the RecordSet.

RecordSet

RecordSet(
    Session & rSession,
    const std::string & query,
    RowFormatter::Ptr pRowFormatter = 0
);

Creates the RecordSet.

RecordSet

RecordSet(
    Session & rSession,
    const std::string & query,
    const RowFormatter & rowFormatter
);

Creates the RecordSet.

RecordSet inline

template < class RF > RecordSet(
    Session & rSession,
    const std::string & query,
    const RF & rowFormatter
);

Creates the RecordSet.

Destructor

~RecordSet

~RecordSet();

Destroys the RecordSet.

Member Functions

begin inline

ConstIterator & begin() const;

Returns the const row iterator.

begin

Iterator begin();

Returns the row iterator.

column inline

template < class C > const Column < C > & column(
    const std::string & name
) const;

Returns the reference to the first Column with the specified name.

column inline

template < class C > const Column < C > & column(
    std::size_t pos
) const;

Returns the reference to column at specified position.

columnCount inline

std::size_t columnCount() const;

Returns the number of columns in the recordset.

columnLength inline

std::size_t columnLength(
    std::size_t pos
) const;

Returns column maximum length for the column at specified position.

columnLength

std::size_t columnLength(
    const std::string & name
) const;

Returns column maximum length for the column with specified name.

columnName inline

const std::string & columnName(
    std::size_t pos
) const;

Returns column name for the column at specified position.

columnPrecision inline

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).

columnPrecision

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).

columnType inline

MetaColumn::ColumnDataType columnType(
    std::size_t pos
) const;

Returns the type for the column at specified position.

columnType

MetaColumn::ColumnDataType columnType(
    const std::string & name
) const;

Returns the type for the column with specified name.

copy

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.

copyNames

std::ostream & copyNames(
    std::ostream & os
) const;

Copies the column names to the target output stream. Copied string is formatted by the current RowFormatter.

copyValues

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.

end inline

ConstIterator & end() const;

Returns the const row iterator.

end

Iterator end();

Returns the row iterator.

extractedRowCount inline

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.

formatNames inline

void formatNames() const;

Formats names using the current RowFormatter.

formatValues

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.

getTotalRowCount inline

std::size_t getTotalRowCount() const;

Deprecated. This function issc_deprecated.

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.

isFiltered

bool isFiltered() const;

Returns true if recordset is filtered.

isNull inline

bool isNull(
    const std::string & name
) const;

Returns true if column value of the current row is null.

moveFirst

bool moveFirst();

Moves the row cursor to the first row.

Returns true if there is at least one row in the RecordSet, false otherwise.

moveLast

bool moveLast();

Moves the row cursor to the last row.

Returns true if there is at least one row in the RecordSet, false otherwise.

moveNext

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.

movePrevious

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.

nvl inline

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.

nvl inline

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.

operator = inline

RecordSet & operator = (
    const Statement & stmt
);

Assignment operator.

operator =

RecordSet & operator = (
    const RecordSet & other
);

Assignment operator.

operator =

RecordSet & operator = (
    RecordSet && other
) noexcept;

Move assignment.

operator []

Poco::Dynamic::Var operator[] (
    const std::string & name
);

Returns the value in the named column of the current row.

operator []

Poco::Dynamic::Var operator[] (
    std::size_t index
);

Returns the value in the named column of the current row.

reset

void reset(
    const Statement & stmt
);

Don't hide base class method. Resets the RecordSet and assigns a new statement. Should be called after the given statement has been reset, assigned a new SQL statement, and executed.

Does not remove the associated RowFilter or RowFormatter.

row

Row & row(
    std::size_t pos
);

Returns reference to row at position pos. Rows are lazy-created and cached.

rowCount

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.

setRowFormatter

void setRowFormatter(
    RowFormatter::Ptr pRowFormatter
);

Assigns the row formatter to the statement and all recordset rows.

setTotalRowCount inline

void setTotalRowCount(
    std::size_t totalRowCount
);

Explicitly sets the total row count.

setTotalRowCount

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.

totalRowCount inline

std::size_t totalRowCount() const;

Replaced with subTotalRowCount() and getTotalRowCount().

value inline

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.

value inline

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.

value

Poco::Dynamic::Var value(
    std::size_t col,
    std::size_t row,
    bool checkFiltering = true
) const;

Returns the data value at column, row location.

value

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.

value

Poco::Dynamic::Var value(
    const std::string & name
);

Returns the value in the named column of the current row.

value

Poco::Dynamic::Var value(
    std::size_t index
);

Returns the value in the given column of the current row.

Variables

UNKNOWN_TOTAL_ROW_COUNT static

static const std::size_t UNKNOWN_TOTAL_ROW_COUNT;

Securely control IoT edge devices from anywhere   Connect a Device