// // RecordSet.cpp // // Library: Data // Package: DataCore // Module: RecordSet // // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // and Contributors. // // SPDX-License-Identifier: BSL-1.0 // #include "Poco/Data/RecordSet.h" #include "Poco/Data/RowFilter.h" #include "Poco/Data/Date.h" #include "Poco/Data/Time.h" #include "Poco/Data/DataException.h" #include "Poco/DateTime.h" #include "Poco/UTFString.h" using namespace Poco::Data::Keywords; using Poco::DateTime; using Poco::UTF16String; namespace Poco { namespace Data { const std::size_t RecordSet::UNKNOWN_TOTAL_ROW_COUNT = std::numeric_limits::max(); RecordSet::RecordSet(const Statement& rStatement, RowFormatter::Ptr pRowFormatter): Statement(rStatement), _currentRow(0), _pBegin(new RowIterator(this, 0 == rowsExtracted())), _pEnd(new RowIterator(this, true)), _totalRowCount(UNKNOWN_TOTAL_ROW_COUNT) { if (pRowFormatter) setRowFormatter(pRowFormatter); } RecordSet::RecordSet(Session& rSession, const std::string& query, RowFormatter::Ptr pRowFormatter): Statement((rSession << query, now)), _currentRow(0), _pBegin(new RowIterator(this, 0 == rowsExtracted())), _pEnd(new RowIterator(this, true)), _totalRowCount(UNKNOWN_TOTAL_ROW_COUNT) { if (pRowFormatter) setRowFormatter(pRowFormatter); } RecordSet::RecordSet(const RecordSet& other): Statement(other.impl()), _currentRow(other._currentRow), _pBegin(new RowIterator(this, 0 == rowsExtracted())), _pEnd(new RowIterator(this, true)), _pFilter(other._pFilter), _totalRowCount(other._totalRowCount) { } RecordSet::RecordSet(RecordSet&& other) noexcept: Statement(std::move(other)), _currentRow(std::move(other._currentRow)), _pBegin(std::move(other._pBegin)), _pEnd(std::move(other._pEnd)), _pFilter(std::move(other._pFilter)), _totalRowCount(std::move(other._totalRowCount)) { } RecordSet::~RecordSet() { try { delete _pBegin; delete _pEnd; RowMap::iterator it = _rowMap.begin(); RowMap::iterator end = _rowMap.end(); for (; it != end; ++it) delete it->second; } catch (...) { poco_unexpected(); } } RecordSet& RecordSet::operator = (RecordSet&& other) noexcept { Statement::operator = (std::move(other)); _currentRow = std::move(other._currentRow); _pBegin = std::move(other._pBegin); _pEnd = std::move(other._pEnd); _pFilter = std::move(other._pFilter); _totalRowCount = std::move(other._totalRowCount); return *this; } void RecordSet::reset(const Statement& stmt) { delete _pBegin; _pBegin = 0; delete _pEnd; _pEnd = 0; _currentRow = 0; _totalRowCount = UNKNOWN_TOTAL_ROW_COUNT; RowMap::iterator it = _rowMap.begin(); RowMap::iterator end = _rowMap.end(); for (; it != end; ++it) delete it->second; _rowMap.clear(); Statement::operator = (stmt); _pBegin = new RowIterator(this, 0 == rowsExtracted()); _pEnd = new RowIterator(this, true); } Poco::Dynamic::Var RecordSet::value(std::size_t col, std::size_t row, bool useFilter) const { if (useFilter && isFiltered() && !isAllowed(row)) throw InvalidAccessException("Row not allowed"); if (isNull(col, row)) return Poco::Dynamic::Var(); switch (columnType(col)) { case MetaColumn::FDT_BOOL: return value(col, row, useFilter); case MetaColumn::FDT_INT8: return value(col, row, useFilter); case MetaColumn::FDT_UINT8: return value(col, row, useFilter); case MetaColumn::FDT_INT16: return value(col, row, useFilter); case MetaColumn::FDT_UINT16: return value(col, row, useFilter); case MetaColumn::FDT_INT32: return value(col, row, useFilter); case MetaColumn::FDT_UINT32: return value(col, row, useFilter); case MetaColumn::FDT_INT64: return value(col, row, useFilter); case MetaColumn::FDT_UINT64: return value(col, row, useFilter); case MetaColumn::FDT_FLOAT: return value(col, row, useFilter); case MetaColumn::FDT_DOUBLE: return value(col, row, useFilter); case MetaColumn::FDT_STRING: return value(col, row, useFilter); case MetaColumn::FDT_WSTRING: return value(col, row, useFilter); case MetaColumn::FDT_BLOB: return value(col, row, useFilter); case MetaColumn::FDT_CLOB: return value(col, row, useFilter); case MetaColumn::FDT_DATE: return value(col, row, useFilter); case MetaColumn::FDT_TIME: return value