aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-05-26 20:53:50 -0400
committerAndrew Chow <achow101-github@achow101.com>2020-10-14 11:28:18 -0400
commit010e3659069e6f97dd7b24483f50ed71042b84b0 (patch)
tree9f5058b01439db7be80a3a5d6665f44ca92af0d2 /src/wallet
parentac5c1617e7f4273daf24c24da1f6bc5ef5ab2d2b (diff)
Implement SQLiteDatabase::TxnBegin, TxnCommit, and TxnAbort
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/sqlite.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp
index 8ad82743ab..1889313dd5 100644
--- a/src/wallet/sqlite.cpp
+++ b/src/wallet/sqlite.cpp
@@ -431,17 +431,32 @@ void SQLiteBatch::CloseCursor()
bool SQLiteBatch::TxnBegin()
{
- return false;
+ if (!m_database.m_db || sqlite3_get_autocommit(m_database.m_db) == 0) return false;
+ int res = sqlite3_exec(m_database.m_db, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
+ if (res != SQLITE_OK) {
+ LogPrintf("SQLiteBatch: Failed to begin the transaction\n");
+ }
+ return res == SQLITE_OK;
}
bool SQLiteBatch::TxnCommit()
{
- return false;
+ if (!m_database.m_db || sqlite3_get_autocommit(m_database.m_db) != 0) return false;
+ int res = sqlite3_exec(m_database.m_db, "COMMIT TRANSACTION", nullptr, nullptr, nullptr);
+ if (res != SQLITE_OK) {
+ LogPrintf("SQLiteBatch: Failed to commit the transaction\n");
+ }
+ return res == SQLITE_OK;
}
bool SQLiteBatch::TxnAbort()
{
- return false;
+ if (!m_database.m_db || sqlite3_get_autocommit(m_database.m_db) != 0) return false;
+ int res = sqlite3_exec(m_database.m_db, "ROLLBACK TRANSACTION", nullptr, nullptr, nullptr);
+ if (res != SQLITE_OK) {
+ LogPrintf("SQLiteBatch: Failed to abort the transaction\n");
+ }
+ return res == SQLITE_OK;
}
bool ExistsSQLiteDatabase(const fs::path& path)