summaryrefslogtreecommitdiff
path: root/libsqlitepp/sqlite-connection.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-29 05:16:51 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-29 06:00:08 +0000
commitfd28011455bd9552150031e9f4a69f5b185b4ae2 (patch)
treef1bfa778f310c387fe2645527c6065436b27e903 /libsqlitepp/sqlite-connection.cpp
parentAdd missing override attribute (diff)
downloadlibdbpp-sqlite-1.0.0.tar.bz2
libdbpp-sqlite-1.0.0.tar.xz
libdbpp-sqlite-1.0.0.zip
Improve and centralise transaction handling logiclibdbpp-sqlite-1.0.0
Diffstat (limited to 'libsqlitepp/sqlite-connection.cpp')
-rw-r--r--libsqlitepp/sqlite-connection.cpp57
1 files changed, 12 insertions, 45 deletions
diff --git a/libsqlitepp/sqlite-connection.cpp b/libsqlitepp/sqlite-connection.cpp
index a284a2e..6545918 100644
--- a/libsqlitepp/sqlite-connection.cpp
+++ b/libsqlitepp/sqlite-connection.cpp
@@ -8,9 +8,7 @@ SQLite::ConnectionError::ConnectionError(sqlite3 * db) :
{
}
-SQLite::Connection::Connection(const std::string & str) :
- txDepth(0),
- rolledback(false)
+SQLite::Connection::Connection(const std::string & str)
{
if (sqlite3_open(str.c_str(), &db) != SQLITE_OK) {
ConnectionError err(db);
@@ -25,58 +23,27 @@ SQLite::Connection::~Connection()
}
void
-SQLite::Connection::finish() const
+SQLite::Connection::beginTxInt()
{
- if (txDepth != 0) {
- rollbackTx();
- throw DB::TransactionStillOpen();
+ if (sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
+ throw Error(db);
}
}
-int
-SQLite::Connection::beginTx() const
-{
- if (txDepth == 0) {
- if (sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
- throw Error(db);
- }
- rolledback = false;
- }
- return ++txDepth;
-}
-
-int
-SQLite::Connection::commitTx() const
+void
+SQLite::Connection::commitTxInt()
{
- if (rolledback) {
- return rollbackTx();
- }
- if (--txDepth == 0) {
- if (sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
- throw Error(db);
- }
+ if (sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
+ throw Error(db);
}
- return txDepth;
}
-int
-SQLite::Connection::rollbackTx() const
+void
+SQLite::Connection::rollbackTxInt()
{
- if (--txDepth == 0) {
- if (sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
- throw Error(db);
- }
- }
- else {
- rolledback = true;
+ if (sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
+ throw Error(db);
}
- return txDepth;
-}
-
-bool
-SQLite::Connection::inTx() const
-{
- return txDepth;
}
DB::BulkDeleteStyle