Commit 9d48d196 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[1183] make sure getNext() when done does not error

parent 6318db7d
......@@ -148,6 +148,9 @@ public:
* \throw DataSourceError if there's database-related error. If the
* exception (or any other in case of derived class) is thrown,
* the iterator can't be safely used any more.
* \return true if a record was found, and the columns array was
* updated. false if there was no more data, in which case
* the columns array is untouched.
*/
virtual bool getNext(std::string (&columns)[COLUMN_COUNT]) = 0;
};
......
......@@ -369,6 +369,11 @@ public:
bool getNext(std::string (&data)[COLUMN_COUNT]) {
// If there's another row, get it
// If finalize has been called (e.g. when previous getNext() got
// SQLITE_DONE), directly return false
if (statement_ == NULL) {
return false;
}
const int rc(sqlite3_step(statement_));
if (rc == SQLITE_ROW) {
// For both types, we copy the first four columns
......
......@@ -190,6 +190,9 @@ TEST_F(SQLite3Access, iterator) {
// Check there's no other
EXPECT_FALSE(context->getNext(data));
// And make sure calling it again won't cause problems.
EXPECT_FALSE(context->getNext(data));
}
TEST(SQLite3Open, getDBNameExample2) {
......@@ -321,6 +324,9 @@ TEST_F(SQLite3Access, getRecords) {
checkRecordRow(columns, "RRSIG", "3600", "DNSKEY",
"DNSKEY 5 2 3600 20100322084538 20100220084538 "
"33495 example.com. FAKEFAKEFAKEFAKE", "");
// check that another getNext does not cause problems
EXPECT_FALSE(context->getNext(columns));
}
} // end anonymous namespace
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment