From dd8ab8890f4173677a2c819a73bee630200fd338 Mon Sep 17 00:00:00 2001 From: randomdan Date: Sun, 8 Dec 2013 15:54:52 +0000 Subject: Add savepoint support to core DB connector Add a savepoint wrapper around sql merge --- libdbpp/connection.cpp | 33 +++++++++++++++++++++++++++++++++ libdbpp/connection.h | 4 ++++ 2 files changed, 37 insertions(+) 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; -- cgit v1.2.3