diff --git a/Data/SQLite/testsuite/src/SQLiteTest.cpp b/Data/SQLite/testsuite/src/SQLiteTest.cpp index e0998b8ef9..824212732a 100755 --- a/Data/SQLite/testsuite/src/SQLiteTest.cpp +++ b/Data/SQLite/testsuite/src/SQLiteTest.cpp @@ -3684,7 +3684,6 @@ void SQLiteTest::testRecordsetCopyMove() session << "INSERT INTO Vectors VALUES (?,?,?)", use(v), now; RecordSet rset(session, "SELECT * FROM Vectors"); - std::ostringstream osLoop; RecordSet::Iterator it = rset.begin(); RecordSet::Iterator end = rset.end(); @@ -3694,11 +3693,11 @@ void SQLiteTest::testRecordsetCopyMove() osLoop << *it; } assertTrue(!osLoop.str().empty()); - std::ostringstream osCopy; std::copy(rset.begin(), rset.end(), std::ostream_iterator(osCopy)); assertTrue(osLoop.str() == osCopy.str()); + // copy RecordSet rsetCopy(rset); osLoop.str(""); it = rsetCopy.begin(); @@ -3713,10 +3712,9 @@ void SQLiteTest::testRecordsetCopyMove() osCopy.str(""); std::copy(rsetCopy.begin(), rsetCopy.end(), std::ostream_iterator(osCopy)); assertTrue(osLoop.str() == osCopy.str()); - /* + + // move RecordSet rsetMove(std::move(rsetCopy)); - rsetCopy.reset(session); - assertEqual(0, rsetCopy.rowCount()); osLoop.str(""); it = rsetMove.begin(); end = rsetMove.end(); @@ -3730,7 +3728,24 @@ void SQLiteTest::testRecordsetCopyMove() osCopy.str(""); std::copy(rsetMove.begin(), rsetMove.end(), std::ostream_iterator(osCopy)); assertTrue(osLoop.str() == osCopy.str()); - */ + + // moved from object must remain in valid unspecified state + // and can be reused + assertEqual(0, rsetCopy.rowCount()); + rsetCopy = (session << "SELECT * FROM Vectors", now); + assertEqual(v.size(), rsetCopy.rowCount()); + osLoop.str(""); + it = rsetCopy.begin(); + end = rsetCopy.end(); + for (int i = 1; it != end; ++it, ++i) + { + assertTrue(it->get(0) == i); + osLoop << *it; + } + assertTrue(!osLoop.str().empty()); + osCopy.str(""); + std::copy(rsetCopy.begin(), rsetCopy.end(), std::ostream_iterator(osCopy)); + assertTrue(osLoop.str() == osCopy.str()); } diff --git a/Data/src/RecordSet.cpp b/Data/src/RecordSet.cpp index 9117d97269..df30eac826 100644 --- a/Data/src/RecordSet.cpp +++ b/Data/src/RecordSet.cpp @@ -60,7 +60,7 @@ RecordSet::RecordSet(Session& rSession, RecordSet::RecordSet(const RecordSet& other): - Statement(other.impl()), + Statement(other), _currentRow(other._currentRow), _pBegin(new RowIterator(this, 0 == rowsExtracted())), _pEnd(new RowIterator(this, true)), @@ -72,17 +72,18 @@ RecordSet::RecordSet(const RecordSet& other): RecordSet::RecordSet(RecordSet&& other) noexcept: - Statement(other.impl()), + Statement(std::move(other)), _currentRow(other._currentRow), - _pBegin(other._pBegin), - _pEnd(other._pEnd), + _pBegin(new RowIterator(this, 0 == rowsExtracted())), + _pEnd(new RowIterator(this, true)), _rowMap(std::move(other._rowMap)), _pFilter(other._pFilter), - _totalRowCount(std::move(other._totalRowCount)) + _totalRowCount(other._totalRowCount) { - other.clear(); other._currentRow = 0; + delete other._pBegin; other._pBegin = nullptr; + delete other._pEnd; other._pEnd = nullptr; other._rowMap.clear(); other._pFilter.reset(); @@ -108,10 +109,19 @@ 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); + other._currentRow = 0; + _pBegin = new RowIterator(this, 0 == rowsExtracted()); + delete other._pBegin; + other._pBegin = nullptr; + _pEnd = new RowIterator(this, true); + delete other._pEnd; + other._pEnd = nullptr; + _rowMap = std::move(other._rowMap); + other._rowMap.clear(); _pFilter = std::move(other._pFilter); + other._pFilter.reset(); _totalRowCount = std::move(other._totalRowCount); + other._totalRowCount = UNKNOWN_TOTAL_ROW_COUNT; return *this; } @@ -499,7 +509,7 @@ Row& RecordSet::row(std::size_t pos) std::size_t RecordSet::rowCount() const { - if (extractions().size() == 0) return 0; + if (!impl() || extractions().size() == 0) return 0; std::size_t rc = subTotalRowCount(); if (!isFiltered()) return rc; diff --git a/Data/src/Statement.cpp b/Data/src/Statement.cpp index 4b5e434fab..c26d904ebe 100644 --- a/Data/src/Statement.cpp +++ b/Data/src/Statement.cpp @@ -70,7 +70,7 @@ Statement::Statement(Statement&& stmt) noexcept: _parseError(std::move(stmt._parseError)), #endif _pImpl(std::move(stmt._pImpl)), - _async(std::move(stmt._async)), + _async(stmt._async), _pResult(std::move(stmt._pResult)), _pAsyncExec(std::move(stmt._pAsyncExec)), _arguments(std::move(stmt._arguments)), @@ -96,6 +96,7 @@ void Statement::clear() noexcept _pRowFormatter = nullptr; _stmtString.clear(); #ifndef POCO_DATA_NO_SQL_PARSER + _pParseResult = nullptr; _parseError.clear(); #endif } @@ -129,7 +130,7 @@ Statement& Statement::operator = (Statement&& stmt) noexcept _pRowFormatter = std::move(stmt._pRowFormatter); stmt._pRowFormatter = nullptr; _stmtString = std::move(stmt._stmtString); - _stmtString.clear(); + stmt._stmtString.clear(); return *this; }