diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-04-15 15:10:58 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-04-15 15:10:58 +0100 |
commit | 2d7c7d4f13c21d7c5b259c8724d3add1f506dd12 (patch) | |
tree | 98e50ec84dc594abd72c6981a3fc115c9fc3fb41 /libmysqlpp | |
parent | Standalone split (diff) | |
download | libdbpp-mysql-1.2.0.tar.bz2 libdbpp-mysql-1.2.0.tar.xz libdbpp-mysql-1.2.0.zip |
C++17libdbpp-mysql-1.2.0
Upgrade everything to C++17
Diffstat (limited to 'libmysqlpp')
-rw-r--r-- | libmysqlpp/my-connection.cpp | 12 | ||||
-rw-r--r-- | libmysqlpp/my-connection.h | 4 | ||||
-rw-r--r-- | libmysqlpp/my-mock.cpp | 9 | ||||
-rw-r--r-- | libmysqlpp/my-mock.h | 3 | ||||
-rw-r--r-- | libmysqlpp/my-selectcommand.cpp | 12 | ||||
-rw-r--r-- | libmysqlpp/unittests/Jamfile.jam | 1 | ||||
-rw-r--r-- | libmysqlpp/unittests/testmysql.cpp | 33 |
7 files changed, 26 insertions, 48 deletions
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<SelectCommand>(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<ModifyCommand>(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<boost::filesystem::path> & 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<Connection>(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<boost::filesystem::path> & ss); - Mock(const std::string & name, const std::vector<boost::filesystem::path> & 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<ColumnBase>(new Column<int64_t, MYSQL_TYPE_LONGLONG>(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared<Column<int64_t, MYSQL_TYPE_LONGLONG>>(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<ColumnBase>(new Column<double, MYSQL_TYPE_DOUBLE>(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared<Column<double, MYSQL_TYPE_DOUBLE>>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: - insertColumn(boost::shared_ptr<ColumnBase>(new Column<MYSQL_TIME, MYSQL_TYPE_DATETIME>(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared<Column<MYSQL_TIME, MYSQL_TYPE_DATETIME>>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_TIME: - insertColumn(boost::shared_ptr<ColumnBase>(new Column<MYSQL_TIME, MYSQL_TYPE_TIME>(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared<Column<MYSQL_TIME, MYSQL_TYPE_TIME>>(fieldDefs[i].name, i, &fields[i])); break; case MYSQL_TYPE_STRING: case MYSQL_TYPE_VAR_STRING: - insertColumn(boost::shared_ptr<ColumnBase>(new StringColumn(fieldDefs[i].name, i, &fields[i], fieldDefs[i].length))); + insertColumn(std::make_shared<StringColumn>(fieldDefs[i].name, i, &fields[i], fieldDefs[i].length)); break; case MYSQL_TYPE_NULL: - insertColumn(boost::shared_ptr<ColumnBase>(new NullColumn(fieldDefs[i].name, i, &fields[i]))); + insertColumn(std::make_shared<NullColumn>(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 <define>BOOST_TEST_DYN_LINK <library>..//dbpp-mysql <library>dbpptestcore + <library>..//adhocutil <library>boost_utf <library>boost_system <library>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 <fstream> #include <boost/date_time/posix_time/posix_time.hpp> -class StandardMockDatabase : public MySQL::Mock { +class StandardMockDatabase : public DB::PluginMock<MySQL::Mock> { public: - StandardMockDatabase() : MySQL::Mock("mysqlmock", { + StandardMockDatabase() : DB::PluginMock<MySQL::Mock>("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); } |