summaryrefslogtreecommitdiff
path: root/libmysqlpp
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
commita9959465c36b04cbf2e0aaeca4ce78ca77e1a445 (patch)
tree80f6282a5f9845d9b0169e765d2f4199b30f9dca /libmysqlpp
parentTidy up (diff)
downloadlibdbpp-mysql-1.0.0.tar.bz2
libdbpp-mysql-1.0.0.tar.xz
libdbpp-mysql-1.0.0.zip
Improve and centralise transaction handling logiclibdbpp-mysql-1.0.0
Diffstat (limited to 'libmysqlpp')
-rw-r--r--libmysqlpp/my-connection.cpp57
-rw-r--r--libmysqlpp/my-connection.h11
-rw-r--r--libmysqlpp/unittests/testmysql.cpp1
3 files changed, 15 insertions, 54 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
diff --git a/libmysqlpp/my-connection.h b/libmysqlpp/my-connection.h
index 238200e..2ffae0d 100644
--- a/libmysqlpp/my-connection.h
+++ b/libmysqlpp/my-connection.h
@@ -19,11 +19,9 @@ namespace MySQL {
Connection(const std::string & info);
~Connection();
- void finish() const override;
- int beginTx() const override;
- int commitTx() const override;
- int rollbackTx() const override;
- bool inTx() const override;
+ void beginTxInt() override;
+ void commitTxInt() override;
+ void rollbackTxInt() override;
void ping() const override;
DB::BulkDeleteStyle bulkDeleteStyle() const override;
DB::BulkUpdateStyle bulkUpdateStyle() const override;
@@ -42,9 +40,6 @@ namespace MySQL {
private:
my_bool my_true;
- mutable unsigned int txDepth;
- mutable bool rolledback;
-
mutable boost::shared_ptr<LoadContext> ctx;
};
}
diff --git a/libmysqlpp/unittests/testmysql.cpp b/libmysqlpp/unittests/testmysql.cpp
index f8c46b6..00c15aa 100644
--- a/libmysqlpp/unittests/testmysql.cpp
+++ b/libmysqlpp/unittests/testmysql.cpp
@@ -55,7 +55,6 @@ BOOST_AUTO_TEST_CASE( bindAndSend )
mod->bindParamT(5, testInterval);
mod->execute();
delete mod;
- rw->commitTx();
delete rw;
}