mirror of
https://github.com/allankoechke/SQLiteCpp.git
synced 2026-12-02 01:11:35 +00:00
Fix Savepoint comments and file formatting
Improved Savepoint description, it was mostly copy-pasted from Transaction with missing bits of information Conform to the SQLiteCpp code style, mainly braces have to be located on their own line
This commit is contained in:
@@ -16,11 +16,13 @@
|
||||
#include <SQLiteCpp/Savepoint.h>
|
||||
#include <SQLiteCpp/Statement.h>
|
||||
|
||||
namespace SQLite {
|
||||
namespace SQLite
|
||||
{
|
||||
|
||||
// Begins the SQLite savepoint
|
||||
Savepoint::Savepoint(Database& aDatabase, const std::string& aName)
|
||||
: mDatabase(aDatabase), msName(aName) {
|
||||
: mDatabase(aDatabase), msName(aName)
|
||||
{
|
||||
// workaround because you cannot bind to SAVEPOINT
|
||||
// escape name for use in query
|
||||
Statement stmt(mDatabase, "SELECT quote(?)");
|
||||
@@ -32,33 +34,46 @@ Savepoint::Savepoint(Database& aDatabase, const std::string& aName)
|
||||
}
|
||||
|
||||
// Safely rollback the savepoint if it has not been committed.
|
||||
Savepoint::~Savepoint() {
|
||||
if (!mbReleased) {
|
||||
try {
|
||||
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.
|
||||
}
|
||||
catch (SQLite::Exception&)
|
||||
{
|
||||
// Never throw an exception in a destructor: error if already released,
|
||||
// but no harm is caused by this.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Release the savepoint and commit
|
||||
void Savepoint::release() {
|
||||
if (!mbReleased) {
|
||||
void Savepoint::release()
|
||||
{
|
||||
if (!mbReleased)
|
||||
{
|
||||
mDatabase.exec(std::string("RELEASE SAVEPOINT ") + msName);
|
||||
mbReleased = true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
throw SQLite::Exception("Savepoint already released.");
|
||||
}
|
||||
}
|
||||
|
||||
// Rollback the savepoint
|
||||
void Savepoint::rollback() {
|
||||
if (!mbReleased) {
|
||||
// Rollback to the savepoint, but don't release it
|
||||
void Savepoint::rollback()
|
||||
{
|
||||
if (!mbReleased)
|
||||
{
|
||||
mDatabase.exec(std::string("ROLLBACK TO SAVEPOINT ") + msName);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
throw SQLite::Exception("Savepoint already released.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user