Skip to content
Snippets Groups Projects
Commit 4f2835d8 authored by Steven Murray's avatar Steven Murray
Browse files

Conn::createStmt() now longer returns a raw pointer

parent 54413f02
No related branches found
No related tags found
No related merge requests found
......@@ -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(),
......
......@@ -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());
......
......@@ -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:
......
......@@ -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());
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment