wallet: sqlite: there is no need to have exclusive locking when mocking

For in-memory SQLite databases, exclusive locking is generally not
necessary because in-memory dbs are private to the connection that
created them.
This commit is contained in:
brunoerg 2024-12-10 18:18:21 -03:00
parent ba8d151fe0
commit 72a424e60a

View file

@ -278,15 +278,18 @@ void SQLiteDatabase::Open()
// Acquire an exclusive lock on the database // Acquire an exclusive lock on the database
// First change the locking mode to exclusive // First change the locking mode to exclusive
SetPragma(m_db, "locking_mode", "exclusive", "Unable to change database locking mode to exclusive"); int ret;
// Now begin a transaction to acquire the exclusive lock. This lock won't be released until we close because of the exclusive locking mode. if (!m_mock) {
int ret = sqlite3_exec(m_db, "BEGIN EXCLUSIVE TRANSACTION", nullptr, nullptr, nullptr); SetPragma(m_db, "locking_mode", "exclusive", "Unable to change database locking mode to exclusive");
if (ret != SQLITE_OK) { // Now begin a transaction to acquire the exclusive lock. This lock won't be released until we close because of the exclusive locking mode.
throw std::runtime_error("SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of " CLIENT_NAME "?\n"); ret = sqlite3_exec(m_db, "BEGIN EXCLUSIVE TRANSACTION", nullptr, nullptr, nullptr);
} if (ret != SQLITE_OK) {
ret = sqlite3_exec(m_db, "COMMIT", nullptr, nullptr, nullptr); throw std::runtime_error("SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of " CLIENT_NAME "?\n");
if (ret != SQLITE_OK) { }
throw std::runtime_error(strprintf("SQLiteDatabase: Unable to end exclusive lock transaction: %s\n", sqlite3_errstr(ret))); ret = sqlite3_exec(m_db, "COMMIT", nullptr, nullptr, nullptr);
if (ret != SQLITE_OK) {
throw std::runtime_error(strprintf("SQLiteDatabase: Unable to end exclusive lock transaction: %s\n", sqlite3_errstr(ret)));
}
} }
// Enable fullfsync for the platforms that use it // Enable fullfsync for the platforms that use it