From 3bc5964793f1700551b7db8107a939c98f1d1be1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 13 Jun 2021 21:29:25 +0100 Subject: Add transaction support --- lib/input/mysqlConn.cpp | 20 ++++++++++++++++++++ lib/input/mysqlConn.h | 4 ++++ 2 files changed, 24 insertions(+) (limited to 'lib/input') diff --git a/lib/input/mysqlConn.cpp b/lib/input/mysqlConn.cpp index 362f9ea..99c2891 100644 --- a/lib/input/mysqlConn.cpp +++ b/lib/input/mysqlConn.cpp @@ -52,4 +52,24 @@ namespace MyGrate::Input { { return std::make_unique(q, this); } + + void + MySQLConn::beginTx() + { + verify(!mysql_autocommit(this, false), "Auto commit off", this); + } + + void + MySQLConn::commitTx() + { + verify(!mysql_commit(this), "Commit", this); + verify(!mysql_autocommit(this, true), "Auto commit on", this); + } + + void + MySQLConn::rollbackTx() + { + verify(!mysql_rollback(this), "Rollback", this); + verify(!mysql_autocommit(this, true), "Auto commit on", this); + } } diff --git a/lib/input/mysqlConn.h b/lib/input/mysqlConn.h index dfb408f..bd53616 100644 --- a/lib/input/mysqlConn.h +++ b/lib/input/mysqlConn.h @@ -29,6 +29,10 @@ namespace MyGrate::Input { void query(const char * const q, const std::initializer_list &) override; DbPrepStmtPtr prepare(const char * const, std::size_t) override; + + void beginTx() override; + void commitTx() override; + void rollbackTx() override; }; } -- cgit v1.2.3