Repository: bitcoin/bitcoin
File: src/wallet/sqlite.cpp (C++)

Code before:
{
    int res = sqlite3_step(m_cursor_stmt);
    if (res == SQLITE_DONE) {
        return Status::DONE;
    }
    if (res != SQLITE_ROW) {
        LogPrintf("%s: Unable to execute cursor step: %s\n", __func__, sqlite3_errstr(res));
        return Status::FAIL;
    }

    key.clear();
    value.clear();

    // Leftmost column in result is index 0
    key.write(SpanFromBlob(m_cursor_stmt, 0));
    value.write(SpanFromBlob(m_cursor_stmt, 1));
    return Status::MORE;
}

SQLiteCursor::~SQLiteCursor()
{
    sqlite3_clear_bindings(m_cursor_stmt);
    sqlite3_reset(m_cursor_stmt);
    int res = sqlite3_finalize(m_cursor_stmt);
    if (res != SQLITE_OK) {
        LogPrintf("%s: cursor closed but could not finalize cursor statement: %s\n",
                  __func__, sqlite3_errstr(res));
    }
}

std::unique_ptr<DatabaseCursor> SQLiteBatch::GetNewCursor()
{
    if (!m_database.m_db) return nullptr;
    auto cursor = std::make_unique<SQLiteCursor>();

    const char* stmt_text = "SELECT key, value FROM main";
    int res = sqlite3_prepare_v2(m_database.m_db, stmt_text, -1, &cursor->m_cursor_stmt, nullptr);
    if (res != SQLITE_OK) {
        throw std::runtime_error(strprintf(
            "%s: Failed to setup cursor SQL statement: %s\n", __func__, sqlite3_errstr(res)));
    }

    return cursor;
}

std::unique_ptr<DatabaseCursor> SQLiteBatch::GetNewPrefixCursor(std::span<const std::byte> prefix)
{
    if (!m_database.m_db) return nullptr;

    // To get just the records we want, the SQL statement does a comparison of the binary data
    // where the data must be greater than or equal to the prefix, and less than

Review comment (suggestion):
```suggestion
        LogWarning("Cursor closed but could not finalize cursor statement: %s",
```

Code after:
{
    int res = sqlite3_step(m_cursor_stmt);
    if (res == SQLITE_DONE) {
        return Status::DONE;
    }
    if (res != SQLITE_ROW) {
        LogWarning("Unable to execute cursor step: %s", sqlite3_errstr(res));
        return Status::FAIL;
    }

    key.clear();
    value.clear();

    // Leftmost column in result is index 0
    key.write(SpanFromBlob(m_cursor_stmt, 0));
    value.write(SpanFromBlob(m_cursor_stmt, 1));
    return Status::MORE;
}

SQLiteCursor::~SQLiteCursor()
{
    sqlite3_clear_bindings(m_cursor_stmt);
    sqlite3_reset(m_cursor_stmt);
    int res = sqlite3_finalize(m_cursor_stmt);
    if (res != SQLITE_OK) {
        LogWarning("Cursor closed but could not finalize cursor statement: %s",
                   sqlite3_errstr(res));
    }
}

std::unique_ptr<DatabaseCursor> SQLiteBatch::GetNewCursor()
{
    if (!m_database.m_db) return nullptr;
    auto cursor = std::make_unique<SQLiteCursor>();

    const char* stmt_text = "SELECT key, value FROM main";
    int res = sqlite3_prepare_v2(m_database.m_db, stmt_text, -1, &cursor->m_cursor_stmt, nullptr);
    if (res != SQLITE_OK) {
        throw std::runtime_error(strprintf(
            "%s: Failed to setup cursor SQL statement: %s\n", __func__, sqlite3_errstr(res)));
    }

    return cursor;
}

std::unique_ptr<DatabaseCursor> SQLiteBatch::GetNewPrefixCursor(std::span<const std::byte> prefix)
{
    if (!m_database.m_db) return nullptr;

    // To get just the records we want, the SQL statement does a comparison of the binary data
    // where the data must be greater than or equal to the prefix, and less than