// // RecordSet.cpp // // $Id: //poco/Main/Data/src/RecordSet.cpp#2 $ // // Library: Data // Package: DataCore // Module: RecordSet // // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // and Contributors. // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // #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" using namespace Poco::Data::Keywords; using Poco::DateTime; 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)), _pFilter(0), _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)), _pFilter(0), _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() { delete _pBegin; delete _pEnd; if(_pFilter) _pFilter->release(); RowMap::iterator it = _rowMap.begin(); RowMap::iterator end = _rowMap.end(); for (; it != end; ++it) delete it->second; } 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_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