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 | a9959465c36b04cbf2e0aaeca4ce78ca77e1a445 (patch) | |
tree | 80f6282a5f9845d9b0169e765d2f4199b30f9dca /libmysqlpp/my-connection.cpp | |
parent | Tidy up (diff) | |
download | libdbpp-mysql-a9959465c36b04cbf2e0aaeca4ce78ca77e1a445.tar.bz2 libdbpp-mysql-a9959465c36b04cbf2e0aaeca4ce78ca77e1a445.tar.xz libdbpp-mysql-a9959465c36b04cbf2e0aaeca4ce78ca77e1a445.zip |
Improve and centralise transaction handling logiclibdbpp-mysql-1.0.0
Diffstat (limited to 'libmysqlpp/my-connection.cpp')
-rw-r--r-- | libmysqlpp/my-connection.cpp | 57 |
1 files changed, 12 insertions, 45 deletions
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 |