diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-29 05:16:51 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-29 06:00:08 +0000 |
commit | 2a8c566bee4f12f48a441fd37f64102328eac6d0 (patch) | |
tree | 68d232be8d4a10877ac56268a2e309f39fe4deef /libpqpp/pq-connection.cpp | |
parent | Tidy up (diff) | |
download | libdbpp-postgresql-1.0.0.tar.bz2 libdbpp-postgresql-1.0.0.tar.xz libdbpp-postgresql-1.0.0.zip |
Improve and centralise transaction handling logiclibdbpp-postgresql-1.0.0
Diffstat (limited to 'libpqpp/pq-connection.cpp')
-rw-r--r-- | libpqpp/pq-connection.cpp | 51 |
1 files changed, 9 insertions, 42 deletions
diff --git a/libpqpp/pq-connection.cpp b/libpqpp/pq-connection.cpp index 42fc1aa..e6340d5 100644 --- a/libpqpp/pq-connection.cpp +++ b/libpqpp/pq-connection.cpp @@ -27,9 +27,7 @@ PQ::ConnectionError::ConnectionError(const PGconn * conn) : PQ::Connection::Connection(const std::string & info) : conn(PQconnectdb(info.c_str())), - txDepth(0), - pstmntNo(0), - rolledback(false) + pstmntNo(0) { if (PQstatus(conn) != CONNECTION_OK) { ConnectionError ce(conn); @@ -45,52 +43,21 @@ PQ::Connection::~Connection() } void -PQ::Connection::finish() const +PQ::Connection::beginTxInt() { - if (txDepth != 0) { - rollbackTx(); - throw DB::TransactionStillOpen(); - } -} - -int -PQ::Connection::beginTx() const -{ - if (txDepth == 0) { - checkResultFree(PQexec(conn, "BEGIN"), PGRES_COMMAND_OK); - rolledback = false; - } - return ++txDepth; + checkResultFree(PQexec(conn, "BEGIN"), PGRES_COMMAND_OK); } -int -PQ::Connection::commitTx() const -{ - if (rolledback) { - return rollbackTx(); - } - if (--txDepth == 0) { - checkResultFree(PQexec(conn, "COMMIT"), PGRES_COMMAND_OK); - } - return txDepth; -} - -int -PQ::Connection::rollbackTx() const +void +PQ::Connection::commitTxInt() { - if (--txDepth == 0) { - checkResultFree(PQexec(conn, "ROLLBACK"), PGRES_COMMAND_OK); - } - else { - rolledback = true; - } - return txDepth; + checkResultFree(PQexec(conn, "COMMIT"), PGRES_COMMAND_OK); } -bool -PQ::Connection::inTx() const +void +PQ::Connection::rollbackTxInt() { - return txDepth; + checkResultFree(PQexec(conn, "ROLLBACK"), PGRES_COMMAND_OK); } void |