mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 10:42:13 +02:00
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.
This commit is contained in:
@@ -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<DatabaseCursor> GetNewCursor() override;
|
||||
bool TxnBegin() override;
|
||||
bool TxnCommit() override;
|
||||
bool TxnAbort() override;
|
||||
|
||||
Reference in New Issue
Block a user