diff --git a/rdbms/Conn.hpp b/rdbms/Conn.hpp index 59947106897c4a3a67c43737202cc6d4218b4906..d283c648bd6439cce8b6f2be04ffe7d6bc97b86b 100644 --- a/rdbms/Conn.hpp +++ b/rdbms/Conn.hpp @@ -20,6 +20,8 @@ #include "Stmt.hpp" +#include <memory> + namespace cta { namespace rdbms { @@ -45,7 +47,7 @@ public: * @sql The SQL statement. * @return The prepared statement. */ - virtual Stmt *createStmt(const std::string &sql) = 0; + virtual std::unique_ptr<Stmt> createStmt(const std::string &sql) = 0; /** * Convenience function implemented in Conn around Conn::createStmt(), diff --git a/rdbms/OcciConn.cpp b/rdbms/OcciConn.cpp index 2cc447d380207752c4673744a73e1432024275ec..54b08b2ffaa823bfcaf548566a2f14c68c7bfaa5 100644 --- a/rdbms/OcciConn.cpp +++ b/rdbms/OcciConn.cpp @@ -16,10 +16,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "OcciConn.hpp" -#include "OcciEnv.hpp" -#include "OcciStmt.hpp" #include "common/exception/Exception.hpp" +#include "common/make_unique.hpp" +#include "rdbms/OcciConn.hpp" +#include "rdbms/OcciEnv.hpp" +#include "rdbms/OcciStmt.hpp" #include <stdexcept> #include <string> @@ -79,14 +80,14 @@ oracle::occi::Connection *OcciConn::operator->() const { //------------------------------------------------------------------------------ // createStmt //------------------------------------------------------------------------------ -Stmt *OcciConn::createStmt(const std::string &sql) { +std::unique_ptr<Stmt> OcciConn::createStmt(const std::string &sql) { try { oracle::occi::Statement *const stmt = m_conn->createStatement(sql); if (nullptr == stmt) { throw exception::Exception("oracle::occi::createStatement() returned a nullptr pointer"); } - return new OcciStmt(sql, *this, stmt); + return make_unique<OcciStmt>(sql, *this, stmt); } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + sql + ": " + ex.getMessage().str()); diff --git a/rdbms/OcciConn.hpp b/rdbms/OcciConn.hpp index 1ce6475e37fbc729fead3085c2e0af28c46e002b..cdde2f8f9085f1832e7f556cfe9afa0c61beaf56 100644 --- a/rdbms/OcciConn.hpp +++ b/rdbms/OcciConn.hpp @@ -52,12 +52,12 @@ public: /** * Destructor. */ - ~OcciConn() throw(); + ~OcciConn() throw() override; /** * Idempotent close() method. The destructor calls this method. */ - virtual void close(); + virtual void close() override; /** * Returns the underlying OCCI connection. @@ -81,17 +81,17 @@ public: * @sql The SQL statement. * @return The prepared statement. */ - virtual Stmt *createStmt(const std::string &sql); + virtual std::unique_ptr<Stmt> createStmt(const std::string &sql) override; /** * Commits the current transaction. */ - virtual void commit(); + virtual void commit() override; /** * Rolls back the current transaction. */ - virtual void rollback(); + virtual void rollback() override; private: diff --git a/rdbms/SqliteConn.cpp b/rdbms/SqliteConn.cpp index e1ed257e811282760ec88081170d7926c9414ee4..a0970e401c61e559f193bfa9615ff1e80a22003f 100644 --- a/rdbms/SqliteConn.cpp +++ b/rdbms/SqliteConn.cpp @@ -17,9 +17,10 @@ */ #include "catalogue/RdbmsCatalogueSchema.hpp" -#include "SqliteConn.hpp" -#include "SqliteStmt.hpp" #include "common/exception/Exception.hpp" +#include "common/make_unique.hpp" +#include "rdbms/SqliteConn.hpp" +#include "rdbms/SqliteStmt.hpp" #include <stdexcept> #include <string> @@ -78,7 +79,7 @@ void SqliteConn::close() { //------------------------------------------------------------------------------ // createStmt //------------------------------------------------------------------------------ -Stmt *SqliteConn::createStmt(const std::string &sql) { +std::unique_ptr<Stmt> SqliteConn::createStmt(const std::string &sql) { try { std::lock_guard<std::mutex> lock(m_mutex); @@ -91,7 +92,7 @@ Stmt *SqliteConn::createStmt(const std::string &sql) { throw exception::Exception(msg); } - return new SqliteStmt(*this, sql, stmt); + return make_unique<SqliteStmt>(*this, sql, stmt); } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + sql + ": " + ex.getMessage().str()); diff --git a/rdbms/SqliteConn.hpp b/rdbms/SqliteConn.hpp index dda5c30c22ee34721ecf55fb82cefe55913c5f20..6881c8177c09dac2a37cb028e4e63ccc049d4d55 100644 --- a/rdbms/SqliteConn.hpp +++ b/rdbms/SqliteConn.hpp @@ -54,7 +54,7 @@ public: /** * Destructor. */ - ~SqliteConn() throw(); + ~SqliteConn() throw() override; /** * Idempotent close() method. The destructor calls this method. @@ -67,17 +67,17 @@ public: * @sql The SQL statement. * @return The prepared statement. */ - virtual Stmt *createStmt(const std::string &sql); + virtual std::unique_ptr<Stmt> createStmt(const std::string &sql) override; /** * Commits the current transaction. */ - virtual void commit(); + virtual void commit() override; /** * Rolls back the current transaction. */ - virtual void rollback(); + virtual void rollback() override; /** * This ia an SqliteConn specific method that prints the database schema to