summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-12-08 15:54:52 +0000
committerrandomdan <randomdan@localhost>2013-12-08 15:54:52 +0000
commitdd8ab8890f4173677a2c819a73bee630200fd338 (patch)
tree28b29ed3f2e5d11e11cad0b76e47d0059f75fa24
parentUse CXX from the environment (diff)
downloadlibdbpp-dd8ab8890f4173677a2c819a73bee630200fd338.tar.bz2
libdbpp-dd8ab8890f4173677a2c819a73bee630200fd338.tar.xz
libdbpp-dd8ab8890f4173677a2c819a73bee630200fd338.zip
Add savepoint support to core DB connector
Add a savepoint wrapper around sql merge
-rw-r--r--libdbpp/connection.cpp33
-rw-r--r--libdbpp/connection.h4
2 files changed, 37 insertions, 0 deletions
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp
index 5b72467..c42c4fb 100644
--- a/libdbpp/connection.cpp
+++ b/libdbpp/connection.cpp
@@ -1,6 +1,39 @@
#include "connection.h"
+#include "modifycommand.h"
DB::Connection::~Connection()
{
}
+void
+DB::Connection::execute(const std::string & sql) const
+{
+ ModifyCommand * cmd = newModifyCommand(sql);
+ try {
+ cmd->execute(true);
+ delete cmd;
+ }
+ catch (...) {
+ delete cmd;
+ throw;
+ }
+}
+
+void
+DB::Connection::savepoint(const std::string & sp) const
+{
+ execute("SAVEPOINT " + sp);
+}
+
+void
+DB::Connection::rollbackToSavepoint(const std::string & sp) const
+{
+ execute("ROLLBACK TO SAVEPOINT " + sp);
+}
+
+void
+DB::Connection::releaseSavepoint(const std::string & sp) const
+{
+ execute("RELEASE SAVEPOINT " + sp);
+}
+
diff --git a/libdbpp/connection.h b/libdbpp/connection.h
index 9a67cc5..fdd27e9 100644
--- a/libdbpp/connection.h
+++ b/libdbpp/connection.h
@@ -25,10 +25,14 @@ namespace DB {
virtual int commitTx() const = 0;
virtual int rollbackTx() const = 0;
virtual bool inTx() const = 0;
+ virtual void savepoint(const std::string &) const;
+ virtual void rollbackToSavepoint(const std::string &) const;
+ virtual void releaseSavepoint(const std::string &) const;
virtual void ping() const = 0;
virtual BulkDeleteStyle bulkDeleteStyle() const = 0;
virtual BulkUpdateStyle bulkUpdateStyle() const = 0;
+ virtual void execute(const std::string & sql) const;
virtual SelectCommand * newSelectCommand(const std::string & sql) const = 0;
virtual ModifyCommand * newModifyCommand(const std::string & sql) const = 0;