From a9959465c36b04cbf2e0aaeca4ce78ca77e1a445 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 29 Dec 2015 05:16:51 +0000 Subject: Improve and centralise transaction handling logic --- libmysqlpp/my-connection.cpp | 57 ++++++++++---------------------------------- 1 file changed, 12 insertions(+), 45 deletions(-) (limited to 'libmysqlpp/my-connection.cpp') diff --git a/libmysqlpp/my-connection.cpp b/libmysqlpp/my-connection.cpp index c6ab993..687572f 100644 --- a/libmysqlpp/my-connection.cpp +++ b/libmysqlpp/my-connection.cpp @@ -58,9 +58,7 @@ NvpTarget(Opts) OptsTargetMap { }; -MySQL::Connection::Connection(const std::string & str) : - txDepth(0), - rolledback(false) +MySQL::Connection::Connection(const std::string & str) { std::stringstream i(str); Opts o; @@ -84,58 +82,27 @@ MySQL::Connection::~Connection() } void -MySQL::Connection::finish() const +MySQL::Connection::beginTxInt() { - if (txDepth != 0) { - rollbackTx(); - throw DB::TransactionStillOpen(); - } -} - -int -MySQL::Connection::beginTx() const -{ - if (txDepth == 0) { - if (mysql_autocommit(&conn, 0)) { - throw Error(&conn); - } - rolledback = false; + if (mysql_autocommit(&conn, 0)) { + throw Error(&conn); } - return ++txDepth; } -int -MySQL::Connection::commitTx() const +void +MySQL::Connection::commitTxInt() { - if (rolledback) { - return rollbackTx(); - } - if (--txDepth == 0) { - if (mysql_commit(&conn)) { - throw Error(&conn); - } + if (mysql_commit(&conn)) { + throw Error(&conn); } - return txDepth; } -int -MySQL::Connection::rollbackTx() const +void +MySQL::Connection::rollbackTxInt() { - if (--txDepth == 0) { - if (mysql_rollback(&conn)) { - throw Error(&conn); - } - } - else { - rolledback = true; + if (mysql_rollback(&conn)) { + throw Error(&conn); } - return txDepth; -} - -bool -MySQL::Connection::inTx() const -{ - return txDepth; } DB::BulkDeleteStyle -- cgit v1.2.3