db: Change DatabaseCursor::Next to return status enum

Next()'s result is a tri-state - failed, more to go, complete. Replace
the way that this is returned with an enum with values FAIL, MORE, and
DONE rather than with two booleans.
This commit is contained in:
Andrew Chow
2022-11-29 22:34:26 -05:00
parent d79e8dcf29
commit 4aebd832a4
11 changed files with 49 additions and 55 deletions

View File

@@ -470,18 +470,15 @@ bool SQLiteBatch::HasKey(CDataStream&& key)
return res == SQLITE_ROW;
}
bool SQLiteCursor::Next(CDataStream& key, CDataStream& value, bool& complete)
DatabaseCursor::Status SQLiteCursor::Next(CDataStream& key, CDataStream& value)
{
complete = false;
int res = sqlite3_step(m_cursor_stmt);
if (res == SQLITE_DONE) {
complete = true;
return true;
return Status::DONE;
}
if (res != SQLITE_ROW) {
LogPrintf("%s: Unable to execute cursor step: %s\n", __func__, sqlite3_errstr(res));
return false;
return Status::FAIL;
}
// Leftmost column in result is index 0
@@ -491,7 +488,7 @@ bool SQLiteCursor::Next(CDataStream& key, CDataStream& value, bool& complete)
const std::byte* value_data{AsBytePtr(sqlite3_column_blob(m_cursor_stmt, 1))};
size_t value_data_size(sqlite3_column_bytes(m_cursor_stmt, 1));
value.write({value_data, value_data_size});
return true;
return Status::MORE;
}
SQLiteCursor::~SQLiteCursor()