fixed GH #1203: Poco::Data::RecordSet should be reusable

This commit is contained in:
Guenter Obiltschnig 2016-03-16 23:15:36 +01:00
parent b30da7bcca
commit 9df405b580
2 changed files with 27 additions and 33 deletions

View File

@ -319,6 +319,13 @@ public:
/// Returns true if there is at least one row in the RecordSet,
/// false otherwise.
void reset(const Statement& stmt);
/// 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.
Poco::Dynamic::Var value(const std::string& name) const;
/// Returns the value in the named column of the current row.
@ -534,8 +541,8 @@ inline std::size_t RecordSet::columnCount() const
inline Statement& RecordSet::operator = (const Statement& stmt)
{
_currentRow = 0;
return Statement::operator = (stmt);
reset(stmt);
return *this;
}
@ -663,36 +670,6 @@ inline size_t RecordSet::storageRowCount() const
return impl()->rowsExtracted();
}
/* TODO
namespace Keywords {
inline const std::string& select(const std::string& str)
{
return str;
}
inline const RecordSet& from(const RecordSet& rs)
{
return rs;
}
inline RecordSet from(const Statement& stmt)
{
return RecordSet(stmt);
}
inline const std::string& where(const std::string& str)
{
return str;
}
} // namespace Keywords
*/
} } // namespace Poco::Data

View File

@ -70,6 +70,7 @@ RecordSet::RecordSet(const RecordSet& other):
_pFilter(other._pFilter),
_totalRowCount(other._totalRowCount)
{
if(_pFilter) _pFilter->duplicate();
}
@ -79,7 +80,7 @@ RecordSet::~RecordSet()
{
delete _pBegin;
delete _pEnd;
if(_pFilter) _pFilter->release();
if (_pFilter) _pFilter->release();
RowMap::iterator it = _rowMap.begin();
RowMap::iterator itEnd = _rowMap.end();
@ -92,6 +93,22 @@ RecordSet::~RecordSet()
}
void RecordSet::reset(const Statement& stmt)
{
delete _pBegin;
_pBegin = 0;
delete _pEnd;
_pEnd = 0;
_currentRow = 0;
_totalRowCount = UNKNOWN_TOTAL_ROW_COUNT;
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 dataRow, bool useFilter) const
{
if (useFilter && isFiltered() && !isAllowed(dataRow))