From ffd3c8e7dcf3bee3304d7c28d8102bf343b64c76 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 22 Apr 2018 15:13:33 +0100 Subject: C++17 Updates code largely in-keeping with updates to be C++17 in line with libadhocutil and libdbpp. --- libodbcpp/odbc-connection.cpp | 12 ++++++------ libodbcpp/odbc-connection.h | 4 ++-- libodbcpp/odbc-mock.cpp | 4 ++-- libodbcpp/odbc-mock.h | 2 +- libodbcpp/odbc-selectcommand.cpp | 16 ++++++++-------- libodbcpp/unittests/Jamfile.jam | 1 + libodbcpp/unittests/testodbc.cpp | 26 ++++++-------------------- 7 files changed, 26 insertions(+), 39 deletions(-) (limited to 'libodbcpp') diff --git a/libodbcpp/odbc-connection.cpp b/libodbcpp/odbc-connection.cpp index 48a1118..9a4a82d 100644 --- a/libodbcpp/odbc-connection.cpp +++ b/libodbcpp/odbc-connection.cpp @@ -139,16 +139,16 @@ ODBC::Connection::bulkUpdateStyle() const return thinkUpdStyle; } -DB::SelectCommand * -ODBC::Connection::newSelectCommand(const std::string & sql, const DB::CommandOptions *) +DB::SelectCommandPtr +ODBC::Connection::select(const std::string & sql, const DB::CommandOptionsCPtr &) { - return new ODBC::SelectCommand(*this, sql); + return std::make_shared(*this, sql); } -DB::ModifyCommand * -ODBC::Connection::newModifyCommand(const std::string & sql, const DB::CommandOptions *) +DB::ModifyCommandPtr +ODBC::Connection::modify(const std::string & sql, const DB::CommandOptionsCPtr &) { - return new ODBC::ModifyCommand(*this, sql); + return std::make_shared(*this, sql); } std::string diff --git a/libodbcpp/odbc-connection.h b/libodbcpp/odbc-connection.h index 4a3940e..3574c42 100644 --- a/libodbcpp/odbc-connection.h +++ b/libodbcpp/odbc-connection.h @@ -30,8 +30,8 @@ namespace ODBC { DB::BulkDeleteStyle bulkDeleteStyle() const override; DB::BulkUpdateStyle bulkUpdateStyle() const override; - DB::SelectCommand * newSelectCommand(const std::string & sql, const DB::CommandOptions *) override; - DB::ModifyCommand * newModifyCommand(const std::string & sql, const DB::CommandOptions *) override; + DB::SelectCommandPtr select(const std::string & sql, const DB::CommandOptionsCPtr &) override; + DB::ModifyCommandPtr modify(const std::string & sql, const DB::CommandOptionsCPtr &) override; private: DB::BulkDeleteStyle thinkDelStyle; diff --git a/libodbcpp/odbc-mock.cpp b/libodbcpp/odbc-mock.cpp index 0ab6ee6..cf28570 100644 --- a/libodbcpp/odbc-mock.cpp +++ b/libodbcpp/odbc-mock.cpp @@ -13,10 +13,10 @@ Mock::Mock(const std::string & b, const std::string & masterdb, const std::strin } AdHocFormatter(MockConnStr, "%?;Database=%?"); -DB::Connection * +DB::ConnectionPtr Mock::openConnection() const { - return new Connection(MockConnStr::get(base, testDbName)); + return std::make_shared(MockConnStr::get(base, testDbName)); } Mock::~Mock() diff --git a/libodbcpp/odbc-mock.h b/libodbcpp/odbc-mock.h index f66d09d..442e3d7 100644 --- a/libodbcpp/odbc-mock.h +++ b/libodbcpp/odbc-mock.h @@ -18,7 +18,7 @@ class DLL_PUBLIC Mock : public DB::MockServerDatabase { void DropDatabase() const override; private: - DB::Connection * openConnection() const override; + DB::ConnectionPtr openConnection() const override; }; } diff --git a/libodbcpp/odbc-selectcommand.cpp b/libodbcpp/odbc-selectcommand.cpp index e33b3da..6b28a32 100644 --- a/libodbcpp/odbc-selectcommand.cpp +++ b/libodbcpp/odbc-selectcommand.cpp @@ -43,7 +43,7 @@ ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset) if (SQL_SUCCEEDED(diagrc)) { if (!strncmp((const char*)sqlstatus, "01004", 5)) { for (Columns::iterator i = columns->begin(); i != columns->end(); ++i) { - boost::dynamic_pointer_cast(*i)->resize(); + std::dynamic_pointer_cast(*i)->resize(); } return fetch(SQL_FETCH_RELATIVE, 0); } @@ -57,7 +57,7 @@ ODBC::SelectCommand::fetch(SQLSMALLINT orientation, SQLLEN offset) { bool resized = false; for (Columns::iterator i = columns->begin(); i != columns->end(); ++i) { - resized |= boost::dynamic_pointer_cast(*i)->resize(); + resized |= std::dynamic_pointer_cast(*i)->resize(); } if (resized) { return fetch(SQL_FETCH_RELATIVE, 0); @@ -97,13 +97,13 @@ ODBC::SelectCommand::execute() case SQL_REAL: case SQL_FLOAT: case SQL_DOUBLE: - ncol = insertColumn(DB::ColumnPtr(new FloatingPointColumn(this, colName, col))); + ncol = insertColumn(std::make_shared(this, colName, col)); break; case SQL_SMALLINT: case SQL_INTEGER: case SQL_TINYINT: case SQL_BIGINT: - ncol = insertColumn(DB::ColumnPtr(new SignedIntegerColumn(this, colName, col))); + ncol = insertColumn(std::make_shared(this, colName, col)); break; case SQL_TYPE_TIME: case SQL_INTERVAL_YEAR: @@ -119,21 +119,21 @@ ODBC::SelectCommand::execute() case SQL_INTERVAL_HOUR_TO_MINUTE: case SQL_INTERVAL_HOUR_TO_SECOND: case SQL_INTERVAL_MINUTE_TO_SECOND: - ncol = insertColumn(DB::ColumnPtr(new IntervalColumn(this, colName, col))); + ncol = insertColumn(std::make_shared(this, colName, col)); break; case SQL_TIMESTAMP: case SQL_DATETIME: case SQL_TYPE_DATE: case SQL_TYPE_TIMESTAMP: - ncol = insertColumn(DB::ColumnPtr(new TimeStampColumn(this, colName, col))); + ncol = insertColumn(std::make_shared(this, colName, col)); break; case SQL_UNKNOWN_TYPE: throw DB::ColumnTypeNotSupported(); default: - ncol = insertColumn(DB::ColumnPtr(new CharArrayColumn(this, colName, col, bindSize))); + ncol = insertColumn(std::make_shared(this, colName, col, bindSize)); break; }; - boost::dynamic_pointer_cast(ncol)->bind(); + std::dynamic_pointer_cast(ncol)->bind(); } } diff --git a/libodbcpp/unittests/Jamfile.jam b/libodbcpp/unittests/Jamfile.jam index 1d64f69..523c64a 100644 --- a/libodbcpp/unittests/Jamfile.jam +++ b/libodbcpp/unittests/Jamfile.jam @@ -13,6 +13,7 @@ run ROOT=\"$(me)\" BOOST_TEST_DYN_LINK ..//dbpp-odbc + ..//adhocutil dbpptestcore boost_utf boost_filesystem diff --git a/libodbcpp/unittests/testodbc.cpp b/libodbcpp/unittests/testodbc.cpp index 77f0a71..f235cfb 100644 --- a/libodbcpp/unittests/testodbc.cpp +++ b/libodbcpp/unittests/testodbc.cpp @@ -11,18 +11,12 @@ #include #include -class StandardMockDatabase : public ODBC::Mock { +class StandardMockDatabase : public DB::PluginMock { public: - StandardMockDatabase() : ODBC::Mock("Driver=psqlodbcw.so;uid=postgres;servername=/run/postgresql", "Database=postgres", "odbcmock", { - rootDir / "odbcschema.sql" }) + StandardMockDatabase() : DB::PluginMock( "odbcmock", { rootDir / "odbcschema.sql" }, + "Driver=psqlodbcw.so;uid=postgres;servername=/run/postgresql", "Database=postgres") { } - - void DropDatabase() const override - { - master->execute("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '" + testDbName + "'"); - ODBC::Mock::DropDatabase(); - } }; BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); @@ -43,30 +37,26 @@ BOOST_AUTO_TEST_CASE( transactions ) BOOST_REQUIRE_EQUAL(true, ro->inTx()); ro->commitTx(); BOOST_REQUIRE_EQUAL(false, ro->inTx()); - - delete ro; } BOOST_AUTO_TEST_CASE( bindAndSend ) { auto rw = DB::MockDatabase::openConnectionTo("odbcmock"); - auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?)"); + auto mod = rw->modify("INSERT INTO test VALUES(?, ?, ?, ?, ?)"); mod->bindParamI(0, testInt); mod->bindParamF(1, testDouble); mod->bindParamS(2, testString); mod->bindParamB(3, testBool); mod->bindParamT(4, testDateTime); mod->execute(); - delete mod; - delete rw; } BOOST_AUTO_TEST_CASE( bindAndSelect ) { auto ro = DB::MockDatabase::openConnectionTo("odbcmock"); - auto select = ro->newSelectCommand("SELECT * FROM test WHERE id = ?"); + auto select = ro->select("SELECT * FROM test WHERE id = ?"); select->bindParamI(0, testInt); select->execute(); int rows = 0; @@ -78,16 +68,14 @@ BOOST_AUTO_TEST_CASE( bindAndSelect ) assertColumnValueHelper(*select, 4, testDateTime); rows += 1; } - delete select; BOOST_REQUIRE_EQUAL(1, rows); - delete ro; } BOOST_AUTO_TEST_CASE( bindAndSelectOther ) { auto ro = DB::MockDatabase::openConnectionTo("odbcmock"); - auto select = ro->newSelectCommand("SELECT * FROM test WHERE id != ?"); + auto select = ro->select("SELECT * FROM test WHERE id != ?"); select->bindParamI(0, testInt); select->execute(); int rows = 0; @@ -99,9 +87,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0})); rows += 1; } - delete select; BOOST_REQUIRE_EQUAL(1, rows); - delete ro; } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3