mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Implement SQLiteDatabase::TxnBegin, TxnCommit, and TxnAbort
This commit is contained in:
parent
ac5c1617e7
commit
010e365906
1 changed files with 18 additions and 3 deletions
|
@ -431,17 +431,32 @@ void SQLiteBatch::CloseCursor()
|
||||||
|
|
||||||
bool SQLiteBatch::TxnBegin()
|
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()
|
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()
|
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)
|
bool ExistsSQLiteDatabase(const fs::path& path)
|
||||||
|
|
Loading…
Add table
Reference in a new issue