summaryrefslogtreecommitdiff
path: root/libpqpp/unittests
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-04-24 15:47:33 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-04-24 15:47:33 +0100
commit6340b06110c35b92bfcc780e85537ca5a752a58c (patch)
tree90e66849ef16ee7fac3ae0d00900ae684996002c /libpqpp/unittests
parentIntroduce select base for different kinds of select (diff)
downloadlibdbpp-postgresql-6340b06110c35b92bfcc780e85537ca5a752a58c.tar.bz2
libdbpp-postgresql-6340b06110c35b92bfcc780e85537ca5a752a58c.tar.xz
libdbpp-postgresql-6340b06110c35b92bfcc780e85537ca5a752a58c.zip
Support bulk selects which don't use cursors, always use of RETURNING
Diffstat (limited to 'libpqpp/unittests')
-rw-r--r--libpqpp/unittests/testpq.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp
index 64d60d9..f5cb760 100644
--- a/libpqpp/unittests/testpq.cpp
+++ b/libpqpp/unittests/testpq.cpp
@@ -287,6 +287,37 @@ BOOST_AUTO_TEST_CASE( statementReuse )
delete ro;
}
+BOOST_AUTO_TEST_CASE( bulkSelect )
+{
+ auto ro = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = ro->newSelectCommand("SELECT * FROM test WHERE id > ? --libdbpp:no-cursor");
+ sel->bindParamI(0, 1);
+ int totalInt = 0, count = 0;
+ sel->forEachRow<int64_t>([&totalInt, &count](auto i) {
+ totalInt += i;
+ count += 1;
+ });
+ delete sel;
+ BOOST_REQUIRE_EQUAL(20, totalInt);
+ BOOST_REQUIRE_EQUAL(8, count);
+ delete ro;
+}
+
+BOOST_AUTO_TEST_CASE( insertReturning )
+{
+ auto ro = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = ro->newSelectCommand("INSERT INTO test(id, fl) VALUES(1, 3) RETURNING id + fl --libdbpp:no-cursor");
+ int totalInt = 0, count = 0;
+ sel->forEachRow<int64_t>([&totalInt, &count](auto i) {
+ totalInt += i;
+ count += 1;
+ });
+ delete sel;
+ BOOST_REQUIRE_EQUAL(4, totalInt);
+ BOOST_REQUIRE_EQUAL(1, count);
+ delete ro;
+}
+
BOOST_AUTO_TEST_CASE( closeOnError )
{
auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));