diff options
author | Dan Goodliffe <daniel.goodliffe@pressassociation.com> | 2016-04-21 10:59:36 +0100 |
---|---|---|
committer | Dan Goodliffe <daniel.goodliffe@pressassociation.com> | 2016-04-21 10:59:36 +0100 |
commit | e52b3dccf14a7606b5a19bcd1a763a377b59e873 (patch) | |
tree | 8a2959729b63cac79355e8e26f1d16f9c270ed85 | |
parent | Actually, don't prepare statement upfront during construction as it might not... (diff) | |
download | libdbpp-postgresql-e52b3dccf14a7606b5a19bcd1a763a377b59e873.tar.bz2 libdbpp-postgresql-e52b3dccf14a7606b5a19bcd1a763a377b59e873.tar.xz libdbpp-postgresql-e52b3dccf14a7606b5a19bcd1a763a377b59e873.zip |
Don't attempt to close cursors when in failed transaction (it's failed and result in sigabrt)libdbpp-postgresql-1.0.4
-rw-r--r-- | libpqpp/pq-selectcommand.cpp | 2 | ||||
-rw-r--r-- | libpqpp/unittests/testpq.cpp | 32 |
2 files changed, 33 insertions, 1 deletions
diff --git a/libpqpp/pq-selectcommand.cpp b/libpqpp/pq-selectcommand.cpp index f8f44fd..b049eea 100644 --- a/libpqpp/pq-selectcommand.cpp +++ b/libpqpp/pq-selectcommand.cpp @@ -24,7 +24,7 @@ PQ::SelectCommand::~SelectCommand() if (execRes) { PQclear(execRes); } - if (executed) { + if (executed && PQtransactionStatus(c->conn) != PQTRANS_INERROR) { c->checkResultFree((PQexec(c->conn, s_close.c_str())), PGRES_COMMAND_OK); } if (txOpened) { 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 <boost/date_time/posix_time/posix_time.hpp> #include <pq-error.h> #include <pq-connection.h> +#include <selectcommandUtil.impl.h> 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 ) |