Skip to content

Commit

Permalink
Add release for savepoint after rollabck in destructor for deleting i…
Browse files Browse the repository at this point in the history
…t form sqlite transaction stack.
  • Loading branch information
Сидоров Андрей Алексеевич committed Dec 12, 2022
1 parent 833f007 commit 1a63044
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Savepoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -49,17 +50,16 @@ 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.");
}
}

// Rollback the savepoint
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.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Savepoint_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 1a63044

Please sign in to comment.