summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jamroot.jam4
-rw-r--r--libodbcpp/odbc-connection.cpp12
-rw-r--r--libodbcpp/odbc-connection.h4
-rw-r--r--libodbcpp/odbc-mock.cpp4
-rw-r--r--libodbcpp/odbc-mock.h2
-rw-r--r--libodbcpp/odbc-selectcommand.cpp16
-rw-r--r--libodbcpp/unittests/Jamfile.jam1
-rw-r--r--libodbcpp/unittests/testodbc.cpp26
8 files changed, 29 insertions, 40 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index 94e8583..701484a 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -6,8 +6,10 @@ variant coverage : debug ;
project
: requirements
- <cxxflags>"-std=c++17 -fvisibility=hidden"
+ <cxxflags>"-std=c++17 -fvisibility=hidden -fvisibility-inlines-hidden"
<linkflags>"-Wl,-z,defs,--warn-once,--gc-sections"
+ <variant>release:<cxxflags>"-flto=2"
+ <variant>release:<linkflags>"-flto=2"
<variant>debug:<cxxflags>"-W -Wall -Werror -Wextra"
<variant>coverage:<cxxflags>"--coverage"
<variant>coverage:<linkflags>"--coverage"
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<ODBC::SelectCommand>(*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<ODBC::ModifyCommand>(*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<Connection>(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<Column>(*i)->resize();
+ std::dynamic_pointer_cast<Column>(*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<Column>(*i)->resize();
+ resized |= std::dynamic_pointer_cast<Column>(*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<FloatingPointColumn>(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<SignedIntegerColumn>(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<IntervalColumn>(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<TimeStampColumn>(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<CharArrayColumn>(this, colName, col, bindSize));
break;
};
- boost::dynamic_pointer_cast<Column>(ncol)->bind();
+ std::dynamic_pointer_cast<Column>(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
<define>ROOT=\"$(me)\"
<define>BOOST_TEST_DYN_LINK
<library>..//dbpp-odbc
+ <library>..//adhocutil
<library>dbpptestcore
<library>boost_utf
<library>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 <definedDirs.h>
#include <boost/date_time/posix_time/posix_time.hpp>
-class StandardMockDatabase : public ODBC::Mock {
+class StandardMockDatabase : public DB::PluginMock<ODBC::Mock> {
public:
- StandardMockDatabase() : ODBC::Mock("Driver=psqlodbcw.so;uid=postgres;servername=/run/postgresql", "Database=postgres", "odbcmock", {
- rootDir / "odbcschema.sql" })
+ StandardMockDatabase() : DB::PluginMock<ODBC::Mock>( "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();