diff options
-rw-r--r-- | libdbpp/connection.cpp | 33 | ||||
-rw-r--r-- | libdbpp/connection.h | 4 |
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; |