aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/sqlite.h
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2024-01-08 11:18:25 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2024-01-30 17:26:45 -0300
commitdca874e838c2599bd24433675b291168f8e7b055 (patch)
treeb70355dfe5ba99c5cbd6cd5870831e41433e5f91 /src/wallet/sqlite.h
parentfdf9f66909a354a95f4b7c5f092f0e9fbe1baa7c (diff)
downloadbitcoin-dca874e838c2599bd24433675b291168f8e7b055.tar.xz
sqlite: add ability to interrupt statements
By encapsulating sqlite3_exec into its own standalone method and introducing the 'SQliteExecHandler' class, we enable the ability to test db statements execution failures within the unit test framework. This is used in the following-up commit to exercise a deadlock and improve our wallet db error handling code. Moreover, the future encapsulation of other sqlite functions within this class will contribute to minimize the impact of any future API changes.
Diffstat (limited to 'src/wallet/sqlite.h')
-rw-r--r--src/wallet/sqlite.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/wallet/sqlite.h b/src/wallet/sqlite.h
index f1ce0567e1..de9ba8fd99 100644
--- a/src/wallet/sqlite.h
+++ b/src/wallet/sqlite.h
@@ -36,11 +36,21 @@ public:
Status Next(DataStream& key, DataStream& value) override;
};
+/** Class responsible for executing SQL statements in SQLite databases.
+ * Methods are virtual so they can be overridden by unit tests testing unusual database conditions. */
+class SQliteExecHandler
+{
+public:
+ virtual ~SQliteExecHandler() {}
+ virtual int Exec(SQLiteDatabase& database, const std::string& statement);
+};
+
/** RAII class that provides access to a WalletDatabase */
class SQLiteBatch : public DatabaseBatch
{
private:
SQLiteDatabase& m_database;
+ std::unique_ptr<SQliteExecHandler> m_exec_handler{std::make_unique<SQliteExecHandler>()};
sqlite3_stmt* m_read_stmt{nullptr};
sqlite3_stmt* m_insert_stmt{nullptr};
@@ -61,6 +71,8 @@ public:
explicit SQLiteBatch(SQLiteDatabase& database);
~SQLiteBatch() override { Close(); }
+ void SetExecHandler(std::unique_ptr<SQliteExecHandler>&& handler) { m_exec_handler = std::move(handler); }
+
/* No-op. See comment on SQLiteDatabase::Flush */
void Flush() override {}