From 564d41222d8e4b3c147fb8ab3fa22ca5bbbf8391 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 10 Jan 2016 17:53:38 +0000 Subject: Close select tx after close cursor, add error checking --- libpqpp/pq-selectcommand.cpp | 9 +++------ libpqpp/unittests/testpq.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libpqpp/pq-selectcommand.cpp b/libpqpp/pq-selectcommand.cpp index 6c02fc4..55dc02c 100644 --- a/libpqpp/pq-selectcommand.cpp +++ b/libpqpp/pq-selectcommand.cpp @@ -21,15 +21,12 @@ PQ::SelectCommand::SelectCommand(Connection * conn, const std::string & sql, uns PQ::SelectCommand::~SelectCommand() { + if (executed) { + c->checkResultFree((PQexec(c->conn, s_close.c_str())), PGRES_COMMAND_OK); + } if (txOpened) { c->commitTx(); } - if (executed) { - PQclear(PQexec(c->conn, s_close.c_str())); - if (execRes) { - PQclear(execRes); - } - } } std::string diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index c49fa34..96e5611 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -160,6 +160,15 @@ BOOST_AUTO_TEST_CASE( bulkload ) delete ro; } +BOOST_AUTO_TEST_CASE( nofetch ) +{ + auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto count = ro->newSelectCommand("SELECT * FROM bulktest"); + count->execute(); + delete count; + delete ro; +} + BOOST_AUTO_TEST_CASE( bigIterate ) { auto ro = DB::MockDatabase::openConnectionTo("pqmock"); -- cgit v1.2.3