Add release for savepoint after rollabck in destructor for deleting it form sqlite transaction stack.

This commit is contained in:
Сидоров Андрей Алексеевич 2022-12-12 12:35:34 +03:00
parent 833f007a0b
commit 1a63044624
3 changed files with 5 additions and 5 deletions

View File

@ -92,7 +92,7 @@ void Database::Deleter::operator()(sqlite3* apSQLite)
SQLITECPP_ASSERT(SQLITE_OK == ret, "database is locked"); // See SQLITECPP_ENABLE_ASSERT_HANDLER
}
//Set a busy handler that sleeps for a specified amount of time when a table is locked.
// Set a busy handler that sleeps for a specified amount of time when a table is locked.
void Database::setBusyTimeout(const int aBusyTimeoutMs)
{
const int ret = sqlite3_busy_timeout(getHandle(), aBusyTimeoutMs);

View File

@ -36,6 +36,7 @@ Savepoint::~Savepoint() {
if (!mbReleased) {
try {
rollback();
release();
} catch (SQLite::Exception&) {
// Never throw an exception in a destructor: error if already rolled
// back or released, but no harm is caused by this.
@ -49,7 +50,7 @@ void Savepoint::release() {
mDatabase.exec(std::string("RELEASE SAVEPOINT ") + msName);
mbReleased = true;
} else {
throw SQLite::Exception("Savepoint already released or rolled back.");
throw SQLite::Exception("Savepoint already released.");
}
}
@ -57,9 +58,8 @@ void Savepoint::release() {
void Savepoint::rollback() {
if (!mbReleased) {
mDatabase.exec(std::string("ROLLBACK TO SAVEPOINT ") + msName);
mbReleased = true;
} else {
throw SQLite::Exception("Savepoint already released or rolled back.");
throw SQLite::Exception("Savepoint already released.");
}
}

View File

@ -33,7 +33,7 @@ TEST(Savepoint, commitRollback) {
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
EXPECT_EQ(SQLite::OK, db.getErrorCode());
// Insert a first valu
// Insert a first value
EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'first')"));
EXPECT_EQ(1, db.getLastInsertRowid());