From 63b2ca0dbdae190941d60a55c9cff99d4a75a0e1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 31 May 2021 13:18:17 +0100 Subject: Initial commit of prepstmt, selects, record sets This is full of holes, but all the basics are covered. --- test/test-mysql.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/test-mysql.cpp') diff --git a/test/test-mysql.cpp b/test/test-mysql.cpp index 5a22567..6baf029 100644 --- a/test/test-mysql.cpp +++ b/test/test-mysql.cpp @@ -1,9 +1,18 @@ #define BOOST_TEST_MODULE MySQL #include +#include +#include +#include +#include +#include #include #include +#include #include +#include +#include +#include BOOST_AUTO_TEST_CASE(simple) { @@ -23,3 +32,24 @@ BOOST_AUTO_TEST_CASE(simple) BOOST_CHECK_NO_THROW(c.query("SET @var = ?", {1.2})); BOOST_CHECK_THROW(c.query("SET @var = ?", {MyGrate::Time {}}), std::runtime_error); } + +using SomeSelect = MyGrate::DbStmt<"SELECT * FROM foo">; +using SomeShow = MyGrate::DbStmt<"SHOW MASTER STATUS">; +using SomeUpdate = MyGrate::DbStmt<"UPDATE foo SET blah = ? WHERE bar = ?", MyGrate::ParamMode::QMark>; + +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(SomeShow::paramCount == 0); +static_assert(SomeUpdate::paramCount == 2); + +BOOST_AUTO_TEST_CASE(stmt) +{ + MyGrate::Input::MySQLConn c {"192.168.1.38", "repl", "r3pl", 3306}; + const auto rs {SomeShow::execute(&c)}; + BOOST_REQUIRE(rs); + BOOST_REQUIRE_EQUAL(rs->rows(), 1); + BOOST_REQUIRE_EQUAL(rs->columns(), 4); + BOOST_CHECK(std::get(rs->at(0, 0)).starts_with("mariadb")); + BOOST_CHECK_GE(std::get(rs->at(0, 1)), 4); +} -- cgit v1.2.3