summaryrefslogtreecommitdiff
path: root/test/test-postgresql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-postgresql.cpp')
-rw-r--r--test/test-postgresql.cpp28
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");
+}