From 2d7c7d4f13c21d7c5b259c8724d3add1f506dd12 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Apr 2018 15:10:58 +0100 Subject: C++17 Upgrade everything to C++17 --- libmysqlpp/my-connection.cpp | 12 ++++++------ libmysqlpp/my-connection.h | 4 ++-- libmysqlpp/my-mock.cpp | 9 ++------- libmysqlpp/my-mock.h | 3 +-- libmysqlpp/my-selectcommand.cpp | 12 ++++++------ libmysqlpp/unittests/Jamfile.jam | 1 + libmysqlpp/unittests/testmysql.cpp | 33 ++++++++------------------------- 7 files changed, 26 insertions(+), 48 deletions(-) (limited to 'libmysqlpp') diff --git a/libmysqlpp/my-connection.cpp b/libmysqlpp/my-connection.cpp index acc89cd..da3f3c6 100644 --- a/libmysqlpp/my-connection.cpp +++ b/libmysqlpp/my-connection.cpp @@ -127,16 +127,16 @@ MySQL::Connection::ping() const } -DB::SelectCommand * -MySQL::Connection::newSelectCommand(const std::string & sql, const DB::CommandOptions *) +DB::SelectCommandPtr +MySQL::Connection::select(const std::string & sql, const DB::CommandOptionsCPtr &) { - return new SelectCommand(this, sql); + return std::make_shared(this, sql); } -DB::ModifyCommand * -MySQL::Connection::newModifyCommand(const std::string & sql, const DB::CommandOptions *) +DB::ModifyCommandPtr +MySQL::Connection::modify(const std::string & sql, const DB::CommandOptionsCPtr &) { - return new ModifyCommand(this, sql); + return std::make_shared(this, sql); } namespace MySQL { diff --git a/libmysqlpp/my-connection.h b/libmysqlpp/my-connection.h index f6acb39..0065579 100644 --- a/libmysqlpp/my-connection.h +++ b/libmysqlpp/my-connection.h @@ -26,8 +26,8 @@ namespace MySQL { 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; void beginBulkUpload(const char *, const char *) override; void endBulkUpload(const char *) override; diff --git a/libmysqlpp/my-mock.cpp b/libmysqlpp/my-mock.cpp index 8cf3057..fb00ef5 100644 --- a/libmysqlpp/my-mock.cpp +++ b/libmysqlpp/my-mock.cpp @@ -13,16 +13,11 @@ Mock::Mock(const std::string & master, const std::string & name, const std::vect PlaySchemaScripts(ss); } -Mock::Mock(const std::string & name, const std::vector & ss) : - Mock("options=p2testmysql", name, ss) -{ -} - AdHocFormatter(MockConnStr, "options=p2testmysql;database=%?"); -DB::Connection * +DB::ConnectionPtr Mock::openConnection() const { - return new Connection(MockConnStr::get(testDbName)); + return std::make_shared(MockConnStr::get(testDbName)); } Mock::~Mock() diff --git a/libmysqlpp/my-mock.h b/libmysqlpp/my-mock.h index 0855015..a1dd770 100644 --- a/libmysqlpp/my-mock.h +++ b/libmysqlpp/my-mock.h @@ -10,11 +10,10 @@ namespace MySQL { class DLL_PUBLIC Mock : public DB::MockServerDatabase { public: Mock(const std::string & master, const std::string & name, const std::vector & ss); - Mock(const std::string & name, const std::vector & ss); ~Mock(); private: - DB::Connection * openConnection() const override; + DB::ConnectionPtr openConnection() const override; }; } diff --git a/libmysqlpp/my-selectcommand.cpp b/libmysqlpp/my-selectcommand.cpp index 5be6bf0..248e714 100644 --- a/libmysqlpp/my-selectcommand.cpp +++ b/libmysqlpp/my-selectcommand.cpp @@ -32,28 +32,28 @@ MySQL::SelectCommand::execute() case MYSQL_TYPE_INT24: case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_YEAR: - insertColumn(boost::shared_ptr(new Column(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: - insertColumn(boost::shared_ptr(new Column(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: - insertColumn(boost::shared_ptr(new Column(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_TIME: - insertColumn(boost::shared_ptr(new Column(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_STRING: case MYSQL_TYPE_VAR_STRING: - insertColumn(boost::shared_ptr(new StringColumn(fieldDefs[i].name, i, &fields[i], fieldDefs[i].length))); + insertColumn(std::make_shared(fieldDefs[i].name, i, &fields[i], fieldDefs[i].length)); break; case MYSQL_TYPE_NULL: - insertColumn(boost::shared_ptr(new NullColumn(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_BIT: case MYSQL_TYPE_BLOB: diff --git a/libmysqlpp/unittests/Jamfile.jam b/libmysqlpp/unittests/Jamfile.jam index 167939a..89f3182 100644 --- a/libmysqlpp/unittests/Jamfile.jam +++ b/libmysqlpp/unittests/Jamfile.jam @@ -14,6 +14,7 @@ run BOOST_TEST_DYN_LINK ..//dbpp-mysql dbpptestcore + ..//adhocutil boost_utf boost_system boost_filesystem diff --git a/libmysqlpp/unittests/testmysql.cpp b/libmysqlpp/unittests/testmysql.cpp index 00c15aa..b2e8175 100644 --- a/libmysqlpp/unittests/testmysql.cpp +++ b/libmysqlpp/unittests/testmysql.cpp @@ -12,9 +12,9 @@ #include #include -class StandardMockDatabase : public MySQL::Mock { +class StandardMockDatabase : public DB::PluginMock { public: - StandardMockDatabase() : MySQL::Mock("mysqlmock", { + StandardMockDatabase() : DB::PluginMock("options=p2testmysql", "mysqlmock", { rootDir / "mysqlschema.sql" }) { } @@ -38,15 +38,13 @@ 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("mysqlmock"); - 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); @@ -54,15 +52,13 @@ BOOST_AUTO_TEST_CASE( bindAndSend ) mod->bindParamT(4, testDateTime); mod->bindParamT(5, testInterval); mod->execute(); - delete mod; - delete rw; } BOOST_AUTO_TEST_CASE( bindAndSelect ) { auto ro = DB::MockDatabase::openConnectionTo("mysqlmock"); - 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; @@ -75,16 +71,14 @@ BOOST_AUTO_TEST_CASE( bindAndSelect ) assertColumnValueHelper(*select, 5, testInterval); rows += 1; } - delete select; BOOST_REQUIRE_EQUAL(1, rows); - delete ro; } BOOST_AUTO_TEST_CASE( bindAndSelectOther ) { auto ro = DB::MockDatabase::openConnectionTo("mysqlmock"); - 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; @@ -97,16 +91,14 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) assertColumnValueHelper(*select, 5, boost::posix_time::time_duration(38, 13, 12)); rows += 1; } - delete select; BOOST_REQUIRE_EQUAL(1, rows); - delete ro; } BOOST_AUTO_TEST_CASE( bulkload ) { auto ro = DB::MockDatabase::openConnectionTo("mysqlmock"); - auto count = ro->newSelectCommand("SELECT COUNT(*) FROM bulktest"); + auto count = ro->select("SELECT COUNT(*) FROM bulktest"); // Test empty ro->beginBulkUpload("bulktest", ""); ro->endBulkUpload(NULL); @@ -121,30 +113,24 @@ BOOST_AUTO_TEST_CASE( bulkload ) } ro->endBulkUpload(NULL); assertScalarValueHelper(*count, 800); - - delete count; - delete ro; } BOOST_AUTO_TEST_CASE( bigIterate ) { auto ro = DB::MockDatabase::openConnectionTo("mysqlmock"); - auto count = ro->newSelectCommand("SELECT * FROM bulktest"); + auto count = ro->select("SELECT * FROM bulktest"); unsigned int rows = 0; while (count->fetch()) { rows += 1; } BOOST_REQUIRE_EQUAL(800, rows); - - delete count; - delete ro; } BOOST_AUTO_TEST_CASE( insertId ) { auto ro = DB::MockDatabase::openConnectionTo("mysqlmock"); - auto ins = ro->newModifyCommand("INSERT INTO inserts(num) VALUES(?)"); + auto ins = ro->modify("INSERT INTO inserts(num) VALUES(?)"); ins->bindParamI(0, 4); ins->execute(); BOOST_REQUIRE_EQUAL(1, ro->insertId()); @@ -154,15 +140,12 @@ BOOST_AUTO_TEST_CASE( insertId ) ins->bindParamI(0, -4); ins->execute(); BOOST_REQUIRE_EQUAL(3, ro->insertId()); - delete ins; - delete ro; } BOOST_AUTO_TEST_CASE( errors ) { auto ro = DB::MockDatabase::openConnectionTo("mysqlmock"); BOOST_REQUIRE_THROW(ro->execute("nonsense"), DB::Error); - delete ro; BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("mysql", "server=nohost"), DB::ConnectionError); } -- cgit v1.2.3