From f7f56c2476561240dfe1e30075ab73022b960562 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 4 Jan 2017 00:24:51 +0000 Subject: Tidy clearing of PGresults --- libpqpp/pq-cursorselectcommand.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libpqpp/pq-cursorselectcommand.cpp b/libpqpp/pq-cursorselectcommand.cpp index 952da3e..4ee6e80 100644 --- a/libpqpp/pq-cursorselectcommand.cpp +++ b/libpqpp/pq-cursorselectcommand.cpp @@ -46,7 +46,7 @@ PQ::CursorSelectCommand::execute() c->beginTx(); txOpened = true; } - execRes = c->checkResult( + c->checkResultFree( PQexecParams(c->conn, s_declare.c_str(), values.size(), NULL, &values.front(), &lengths.front(), NULL, 0), PGRES_COMMAND_OK); fetchTuples(); @@ -58,10 +58,6 @@ PQ::CursorSelectCommand::execute() void PQ::CursorSelectCommand::fetchTuples() { - if (execRes) { - PQclear(execRes); - } - execRes = NULL; execRes = c->checkResult(PQexec(c->conn, s_fetch.c_str()), PGRES_TUPLES_OK); nTuples = PQntuples(execRes); tuple = -1; @@ -72,6 +68,9 @@ PQ::CursorSelectCommand::fetch() { execute(); if ((tuple >= (nTuples - 1)) && (nTuples == fTuples)) { + // Delete the previous result set + PQclear(execRes); + execRes = NULL; fetchTuples(); } if (tuple++ < (nTuples - 1)) { -- cgit v1.2.3