summaryrefslogtreecommitdiff
path: root/libpqpp/pq-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
commitfd9ad6023012494356829e9b7642ef4ec07f30a3 (patch)
tree28e8f424645dbd6e39863c5dd9531509740ad913 /libpqpp/pq-connection.cpp
parentTidy up (diff)
downloadlibdbpp-postgresql-fd9ad6023012494356829e9b7642ef4ec07f30a3.tar.bz2
libdbpp-postgresql-fd9ad6023012494356829e9b7642ef4ec07f30a3.tar.xz
libdbpp-postgresql-fd9ad6023012494356829e9b7642ef4ec07f30a3.zip
Improve and centralise transaction handling logic
Diffstat (limited to 'libpqpp/pq-connection.cpp')
-rw-r--r--libpqpp/pq-connection.cpp51
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