From 0dd5980eef6fee02ff9dc61bb4c20b6f3670a93c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 5 Jan 2017 21:02:54 +0000 Subject: Fix bug where prepared statement cache wasn't cleared on connection reset leading to random failure due to prepapred statements not existing --- libpqpp/pq-connection.cpp | 1 + libpqpp/pq-connection.h | 2 +- libpqpp/unittests/testpq.cpp | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'libpqpp') diff --git a/libpqpp/pq-connection.cpp b/libpqpp/pq-connection.cpp index 5b560a9..547923f 100644 --- a/libpqpp/pq-connection.cpp +++ b/libpqpp/pq-connection.cpp @@ -88,6 +88,7 @@ PQ::Connection::ping() const if (inTx()) { throw ConnectionError(conn); } + preparedStatements.clear(); PQreset(conn); if (PQstatus(conn) != CONNECTION_OK) { throw ConnectionError(conn); diff --git a/libpqpp/pq-connection.h b/libpqpp/pq-connection.h index d5cbde6..1659c13 100644 --- a/libpqpp/pq-connection.h +++ b/libpqpp/pq-connection.h @@ -43,7 +43,7 @@ namespace PQ { void checkResultFree(PGresult * res, int expected, int alternative = -1) const; PGconn * conn; - PreparedStatements preparedStatements; + mutable PreparedStatements preparedStatements; private: static bool checkResultInt(PGresult * res, int expected, int alternative); diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index f7c327f..fcf01e3 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -232,6 +232,7 @@ BOOST_AUTO_TEST_CASE( reconnect ) int pid1 = PQbackendPID(pqconn->conn); BOOST_REQUIRE(pid1); ro->ping(); + ro->modify("TRUNCATE TABLE test")->execute(); auto kil = rok->newModifyCommand("SELECT pg_terminate_backend(?)"); kil->bindParamI(0, pid1); kil->execute(); @@ -241,6 +242,7 @@ BOOST_AUTO_TEST_CASE( reconnect ) int pid2 = PQbackendPID(pqconn->conn); BOOST_REQUIRE(pid2); BOOST_REQUIRE(pid1 != pid2); + ro->modify("TRUNCATE TABLE test")->execute(); delete ro; delete rok; } -- cgit v1.2.3