diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-02-26 20:47:35 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-02-26 20:47:35 +0000 |
commit | a221fb5615c6f174d5db463f69377c0829f449ab (patch) | |
tree | 1cd11bbaa9e8acfff21296ed518d5e0ae0be8413 /libpqpp/unittests | |
parent | Reuse prepared statements (diff) | |
download | libdbpp-postgresql-a221fb5615c6f174d5db463f69377c0829f449ab.tar.bz2 libdbpp-postgresql-a221fb5615c6f174d5db463f69377c0829f449ab.tar.xz libdbpp-postgresql-a221fb5615c6f174d5db463f69377c0829f449ab.zip |
Prepare statement upfront during construction
Diffstat (limited to 'libpqpp/unittests')
-rw-r--r-- | libpqpp/unittests/testpq.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index 3d8c804..088910d 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -267,14 +267,22 @@ BOOST_AUTO_TEST_CASE( statementReuse ) auto ro = DB::MockDatabase::openConnectionTo("pqmock"); auto pqconn = dynamic_cast<PQ::Connection *>(ro); BOOST_REQUIRE_EQUAL(pqconn->preparedStatements.size(), 0); + ro->modify("DELETE FROM test")->execute(); + BOOST_REQUIRE_EQUAL(pqconn->preparedStatements.size(), 1); for (int y = 0; y < 4; y += 1) { auto m1 = ro->modify("INSERT INTO test(id) VALUES(?)"); + BOOST_REQUIRE_EQUAL(pqconn->preparedStatements.size(), 2); for (int x = 0; x < 4; x += 1) { m1->bindParamI(0, x); m1->execute(); } } - BOOST_REQUIRE_EQUAL(pqconn->preparedStatements.size(), 1); + BOOST_REQUIRE_EQUAL(pqconn->preparedStatements.size(), 2); + auto select = ro->newSelectCommand("SELECT COUNT(id), SUM(id) FROM test"); + while (select->fetch()) { + assertColumnValueHelper(*select, 0, 16); + assertColumnValueHelper(*select, 1, 24); + } delete ro; } |