From 78d8eeadcf6642eb52b3b178d6da620b0bb34289 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Oct 2023 16:58:13 +0100 Subject: Use unique_ptr for execution results --- libpqpp/pq-cursorselectcommand.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'libpqpp/pq-cursorselectcommand.cpp') diff --git a/libpqpp/pq-cursorselectcommand.cpp b/libpqpp/pq-cursorselectcommand.cpp index 8d3a7bf..bfb69d4 100644 --- a/libpqpp/pq-cursorselectcommand.cpp +++ b/libpqpp/pq-cursorselectcommand.cpp @@ -5,7 +5,6 @@ #include "pq-selectbase.h" #include #include -#include #include #include #include @@ -25,7 +24,7 @@ PQ::CursorSelectCommand::CursorSelectCommand(Connection * conn, const std::strin PQ::CursorSelectCommand::~CursorSelectCommand() { if (executed && PQtransactionStatus(c->conn) != PQTRANS_INERROR) { - c->checkResultFree((PQexec(c->conn, s_close.c_str())), PGRES_COMMAND_OK); + c->checkResult(PQexec(c->conn, s_close.c_str()), PGRES_COMMAND_OK); } } @@ -45,11 +44,11 @@ PQ::CursorSelectCommand::execute() if (s_declare.empty()) { s_declare = mkdeclare(); } - c->checkResultFree(PQexecParams(c->conn, s_declare.c_str(), static_cast(values.size()), nullptr, - values.data(), lengths.data(), formats.data(), binary), + c->checkResult(PQexecParams(c->conn, s_declare.c_str(), static_cast(values.size()), nullptr, values.data(), + lengths.data(), formats.data(), binary), PGRES_COMMAND_OK); fetchTuples(); - createColumns(execRes); + createColumns(); executed = true; } } @@ -59,7 +58,7 @@ PQ::CursorSelectCommand::fetchTuples() { execRes = c->checkResult( PQexecParams(c->conn, s_fetch.c_str(), 0, nullptr, nullptr, nullptr, nullptr, binary), PGRES_TUPLES_OK); - nTuples = static_cast(PQntuples(execRes)); + nTuples = static_cast(PQntuples(execRes.get())); tuple = static_cast(-1); } @@ -69,8 +68,7 @@ PQ::CursorSelectCommand::fetch() execute(); if ((tuple + 1 >= nTuples) && (nTuples == fTuples)) { // Delete the previous result set - PQclear(execRes); - execRes = nullptr; + execRes.reset(); fetchTuples(); } if (++tuple < nTuples) { @@ -78,8 +76,7 @@ PQ::CursorSelectCommand::fetch() } else { PQclear(PQexec(c->conn, s_close.c_str())); - PQclear(execRes); - execRes = nullptr; + execRes.reset(); executed = false; return false; } -- cgit v1.2.3