diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-04-24 15:47:33 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-04-24 15:47:33 +0100 |
commit | 4076ca685941ac433bc91130e29449cef7858fba (patch) | |
tree | 5b219bd316ca89c72a0fa361da849214f312699a /libpqpp/unittests | |
parent | Introduce select base for different kinds of select (diff) | |
download | libdbpp-postgresql-4076ca685941ac433bc91130e29449cef7858fba.tar.bz2 libdbpp-postgresql-4076ca685941ac433bc91130e29449cef7858fba.tar.xz libdbpp-postgresql-4076ca685941ac433bc91130e29449cef7858fba.zip |
Support bulk selects which don't use cursors, always use of RETURNING
Diffstat (limited to 'libpqpp/unittests')
-rw-r--r-- | libpqpp/unittests/testpq.cpp | 31 |
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")); |