From afcde49538230d4f8648e227f8a861b5a1b9a83c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 21 Apr 2016 10:59:36 +0100 Subject: Don't attempt to close cursors when in failed transaction (it's failed and result in sigabrt) --- libpqpp/unittests/testpq.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libpqpp/unittests') diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index 1905192..64d60d9 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -11,6 +11,7 @@ #include #include #include +#include class StandardMockDatabase : public PQ::Mock { public: @@ -286,6 +287,37 @@ BOOST_AUTO_TEST_CASE( statementReuse ) delete ro; } +BOOST_AUTO_TEST_CASE( closeOnError ) +{ + auto ro = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock")); + BOOST_REQUIRE_THROW({ + ro->select("SELECT * FROM test")->forEachRow<>([&ro](){ + ro->execute("nonsense"); + }); + }, DB::Error); + BOOST_REQUIRE_THROW({ + ro->select("SELECT * FROM test")->forEachRow<>([&ro](){ + ro->select("SELECT * FROM test")->forEachRow<>([&ro](){ + ro->execute("nonsense"); + }); + }); + }, DB::Error); + ro->beginTx(); + BOOST_REQUIRE_THROW({ + ro->select("SELECT * FROM test")->forEachRow<>([&ro](){ + ro->execute("nonsense"); + }); + }, DB::Error); + BOOST_REQUIRE_THROW({ + ro->select("SELECT * FROM test")->forEachRow<>([&ro](){ + ro->select("SELECT * FROM test")->forEachRow<>([&ro](){ + ro->execute("nonsense"); + }); + }); + }, DB::Error); + ro->commitTx(); +} + BOOST_AUTO_TEST_SUITE_END(); BOOST_AUTO_TEST_CASE( connfail ) -- cgit v1.2.3