Skip to content

Commit

Permalink
Merge pull request #390 fix incorrect work of savepoint from spoyler/…
Browse files Browse the repository at this point in the history
…save_point

Fix #381
  • Loading branch information
SRombauts authored Dec 15, 2022
2 parents 6ebb328 + 1a63044 commit 343299a
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 @@ -93,7 +93,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 343299a

Please sign in to comment.