diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-24 01:01:30 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-24 01:01:30 +0100 |
commit | 15c1e5566f7ad8448985ca6e52805ceb4ec389a8 (patch) | |
tree | 14908b221d01cca00975da84656adcea57898620 /test/test-postgresql.cpp | |
parent | Minor tidy up of replStream (diff) | |
download | mygrate-15c1e5566f7ad8448985ca6e52805ceb4ec389a8.tar.bz2 mygrate-15c1e5566f7ad8448985ca6e52805ceb4ec389a8.tar.xz mygrate-15c1e5566f7ad8448985ca6e52805ceb4ec389a8.zip |
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.
Diffstat (limited to 'test/test-postgresql.cpp')
-rw-r--r-- | test/test-postgresql.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
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 <boost/test/unit_test.hpp> + +#include <dbTypes.h> +#include <output/pq/pqConn.h> +#include <stdexcept> + +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"); +} |