summaryrefslogtreecommitdiff
path: root/libpqpp/unittests
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-06-05 16:47:06 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-06-05 17:17:09 +0100
commitb9aaad1d4d8be6604c84aa11651b99ac932794af (patch)
tree907695b54295aaf3b25240c8c0cb20d56ecc14c6 /libpqpp/unittests
parentFix memory leak in unit test (diff)
downloadlibdbpp-postgresql-b9aaad1d4d8be6604c84aa11651b99ac932794af.tar.bz2
libdbpp-postgresql-b9aaad1d4d8be6604c84aa11651b99ac932794af.tar.xz
libdbpp-postgresql-b9aaad1d4d8be6604c84aa11651b99ac932794af.zip
Add support for bytea / blob type data
Diffstat (limited to 'libpqpp/unittests')
-rw-r--r--libpqpp/unittests/pqschema.sql3
-rw-r--r--libpqpp/unittests/testpq.cpp24
2 files changed, 27 insertions, 0 deletions
diff --git a/libpqpp/unittests/pqschema.sql b/libpqpp/unittests/pqschema.sql
index 2a7dd09..a79b678 100644
--- a/libpqpp/unittests/pqschema.sql
+++ b/libpqpp/unittests/pqschema.sql
@@ -38,4 +38,7 @@ CREATE TABLE bulktest(
CREATE TABLE idtest(
id serial,
foo int);
+CREATE TABLE blobtest(
+ data bytea,
+ md5 text);
diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp
index 87992ca..97dc22d 100644
--- a/libpqpp/unittests/testpq.cpp
+++ b/libpqpp/unittests/testpq.cpp
@@ -383,6 +383,30 @@ BOOST_AUTO_TEST_CASE( closeOnError )
ro->commitTx();
}
+BOOST_AUTO_TEST_CASE( blobs )
+{
+ auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("PQmock"));
+ std::vector<char> buf(29);
+ memcpy(&buf[0], "This is some binary text data", 29);
+ auto ins = ro->modify("INSERT INTO blobtest(data) VALUES(?)");
+ ins->bindParamBLOB(0, buf);
+ ins->execute();
+
+ ro->execute("UPDATE blobtest SET md5 = md5(data)");
+
+ auto sel = ro->select("SELECT data, md5, length(data) FROM blobtest");
+ for (const auto & r : sel->as<DB::Blob, std::string, int64_t>()) {
+ // Assert the DB understood the insert
+ BOOST_REQUIRE_EQUAL(r.value<2>(), buf.size());
+ BOOST_REQUIRE_EQUAL(r.value<1>(), "37c7c3737f93e8d17e845deff8fa74d2");
+ // Assert the fetch of the data is correct
+ BOOST_REQUIRE_EQUAL(r.value<0>().len, buf.size());
+ std::string str((const char *)r.value<0>().data, r.value<0>().len);
+ BOOST_REQUIRE_EQUAL(str, "This is some binary text data");
+ BOOST_REQUIRE(memcmp(r.value<0>().data, &buf[0], 29) == 0);
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_CASE( connfail )