summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test-mysql.cpp30
-rw-r--r--test/test-postgresql.cpp44
2 files changed, 74 insertions, 0 deletions
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 <boost/test/unit_test.hpp>
+#include <compileTimeFormatter.h>
+#include <cstddef>
+#include <cstdint>
+#include <dbRecordSet.h>
+#include <dbStmt.h>
#include <dbTypes.h>
#include <input/mysqlConn.h>
+#include <memory>
#include <stdexcept>
+#include <string_view>
+#include <type_traits>
+#include <variant>
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<SomeSelect::Return, MyGrate::RecordSetPtr>);
+static_assert(std::is_same_v<SomeShow::Return, MyGrate::RecordSetPtr>);
+static_assert(std::is_same_v<SomeUpdate::Return, std::size_t>);
+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<std::string_view>(rs->at(0, 0)).starts_with("mariadb"));
+ BOOST_CHECK_GE(std::get<int64_t>(rs->at(0, 1)), 4);
+}
diff --git a/test/test-postgresql.cpp b/test/test-postgresql.cpp
index 5940b38..f388ef2 100644
--- a/test/test-postgresql.cpp
+++ b/test/test-postgresql.cpp
@@ -1,9 +1,17 @@
#define BOOST_TEST_MODULE PostgreSQL
#include <boost/test/unit_test.hpp>
+#include <compileTimeFormatter.h>
+#include <cstddef>
+#include <dbRecordSet.h>
+#include <dbStmt.h>
#include <dbTypes.h>
+#include <memory>
#include <output/pq/pqConn.h>
#include <stdexcept>
+#include <string_view>
+#include <type_traits>
+#include <variant>
BOOST_AUTO_TEST_CASE(simple)
{
@@ -26,3 +34,39 @@ BOOST_AUTO_TEST_CASE(simple)
BOOST_CHECK_THROW(c.query("INSERT INTO test VALUES($1)", {MyGrate::Time {}}), std::runtime_error);
c.query("DROP TABLE test");
}
+
+using SomeUpdate = MyGrate::DbStmt<"UPDATE foo SET blah = $2 WHERE bar = $1", MyGrate::ParamMode::DollarNum>;
+using SomeUpdateRtn
+ = MyGrate::DbStmt<"UPDATE foo SET blah = $2 WHERE bar = $1 RETURNING x", MyGrate::ParamMode::DollarNum>;
+using SomeShow = MyGrate::DbStmt<"SHOW all", MyGrate::ParamMode::DollarNum>;
+using SomeIns = MyGrate::DbStmt<"INSERT INTO foo VALUES(..., $87)", MyGrate::ParamMode::DollarNum>;
+
+static_assert(SomeUpdate::paramCount == 2);
+static_assert(std::is_same_v<SomeUpdate::Return, std::size_t>);
+static_assert(SomeUpdateRtn::paramCount == 2);
+static_assert(std::is_same_v<SomeUpdateRtn::Return, MyGrate::RecordSetPtr>);
+static_assert(SomeShow::paramCount == 0);
+static_assert(SomeIns::paramCount == 87);
+static_assert(std::is_same_v<SomeIns::Return, std::size_t>);
+
+BOOST_AUTO_TEST_CASE(stmt)
+{
+ MyGrate::Output::Pq::PqConn c {"user=postgres"};
+ const auto rs {SomeShow::execute(&c)};
+ BOOST_REQUIRE(rs);
+ BOOST_REQUIRE_EQUAL(rs->columns(), 3);
+ BOOST_REQUIRE_GT(rs->rows(), 1);
+ BOOST_CHECK_EQUAL(std::get<std::string_view>(rs->at(0, 0)), "allow_system_table_mods");
+ BOOST_CHECK_EQUAL(std::get<std::string_view>(rs->at(0, 1)), "off");
+}
+
+BOOST_AUTO_TEST_CASE(stmt_reuse)
+{
+ MyGrate::Output::Pq::PqConn c {"user=postgres"};
+ for (int x = 0; x < 10; x++) {
+ const auto rs {SomeShow::execute(&c)};
+ BOOST_REQUIRE(rs);
+ BOOST_CHECK_EQUAL(rs->columns(), 3);
+ BOOST_CHECK_GT(rs->rows(), 1);
+ }
+}