From 7a198bba0a1d0a0f0fd4ca947955cb52b84bdd4b Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 11 Apr 2022 15:14:24 -0400 Subject: wallet: Introduce DatabaseCursor RAII class for managing cursor Instead of having DatabaseBatch deal with opening and closing database cursors, have a separate RAII class that deals with those. For now, DatabaseBatch manages DatabaseCursor, but this will change later. --- src/wallet/sqlite.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/wallet/sqlite.h') diff --git a/src/wallet/sqlite.h b/src/wallet/sqlite.h index 47b7ebb0ec..286ee1613d 100644 --- a/src/wallet/sqlite.h +++ b/src/wallet/sqlite.h @@ -14,19 +14,27 @@ struct bilingual_str; namespace wallet { class SQLiteDatabase; +class SQLiteCursor : public DatabaseCursor +{ +public: + sqlite3_stmt* m_cursor_stmt{nullptr}; + + explicit SQLiteCursor() {} + ~SQLiteCursor() override; + + bool Next(CDataStream& key, CDataStream& value, bool& complete) override; +}; + /** RAII class that provides access to a WalletDatabase */ class SQLiteBatch : public DatabaseBatch { private: SQLiteDatabase& m_database; - bool m_cursor_init = false; - sqlite3_stmt* m_read_stmt{nullptr}; sqlite3_stmt* m_insert_stmt{nullptr}; sqlite3_stmt* m_overwrite_stmt{nullptr}; sqlite3_stmt* m_delete_stmt{nullptr}; - sqlite3_stmt* m_cursor_stmt{nullptr}; void SetupSQLStatements(); @@ -44,9 +52,7 @@ public: void Close() override; - bool StartCursor() override; - bool ReadAtCursor(CDataStream& key, CDataStream& value, bool& complete) override; - void CloseCursor() override; + std::unique_ptr GetNewCursor() override; bool TxnBegin() override; bool TxnCommit() override; bool TxnAbort() override; -- cgit v1.2.3 From 4aebd832a405090c2608e4b60bb4f34501bcea61 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 29 Nov 2022 22:34:26 -0500 Subject: 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. --- src/wallet/sqlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/wallet/sqlite.h') diff --git a/src/wallet/sqlite.h b/src/wallet/sqlite.h index 286ee1613d..23111cda16 100644 --- a/src/wallet/sqlite.h +++ b/src/wallet/sqlite.h @@ -22,7 +22,7 @@ public: explicit SQLiteCursor() {} ~SQLiteCursor() override; - bool Next(CDataStream& key, CDataStream& value, bool& complete) override; + Status Next(CDataStream& key, CDataStream& value) override; }; /** RAII class that provides access to a WalletDatabase */ -- cgit v1.2.3