From 15c1e5566f7ad8448985ca6e52805ceb4ec389a8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 24 May 2021 01:01:30 +0100 Subject: Basic support for queries with bound parameters Bit of a reshuffle to make the types not DB specific, add some basic tests over query execution, no selects yet and no validation anything is actually right. --- test/test-postgresql.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/test-postgresql.cpp (limited to 'test/test-postgresql.cpp') diff --git a/test/test-postgresql.cpp b/test/test-postgresql.cpp new file mode 100644 index 0000000..5940b38 --- /dev/null +++ b/test/test-postgresql.cpp @@ -0,0 +1,28 @@ +#define BOOST_TEST_MODULE PostgreSQL +#include + +#include +#include +#include + +BOOST_AUTO_TEST_CASE(simple) +{ + BOOST_CHECK_THROW(([]() { + MyGrate::Output::Pq::PqConn {"nonsense"}; + }()), + std::runtime_error); + MyGrate::Output::Pq::PqConn c {"user=postgres"}; + BOOST_CHECK_NO_THROW(c.query("SET application_name = ''")); + BOOST_CHECK_NO_THROW(c.query("SET application_name = 'something'")); + BOOST_CHECK_THROW(c.query("SET application_name = "), std::runtime_error); + // BOOST_CHECK_THROW(c.query("SET application_name = $1", {}), std::logic_error); + BOOST_CHECK_NO_THROW(c.query("SET application_name = 'something'", {})); + c.query("DROP TABLE IF EXISTS test"); + c.query("CREATE TABLE test(c text)"); + BOOST_CHECK_NO_THROW(c.query("INSERT INTO test VALUES($1)", {1})); + BOOST_CHECK_NO_THROW(c.query("INSERT INTO test VALUES($1)", {"string_view"})); + BOOST_CHECK_NO_THROW(c.query("INSERT INTO test VALUES($1)", {nullptr})); + BOOST_CHECK_NO_THROW(c.query("INSERT INTO test VALUES($1)", {1.2})); + BOOST_CHECK_THROW(c.query("INSERT INTO test VALUES($1)", {MyGrate::Time {}}), std::runtime_error); + c.query("DROP TABLE test"); +} -- cgit v1.2.3