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-modifycommand.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'libpqpp/pq-modifycommand.cpp') diff --git a/libpqpp/pq-modifycommand.cpp b/libpqpp/pq-modifycommand.cpp index b29fda7..53c3231 100644 --- a/libpqpp/pq-modifycommand.cpp +++ b/libpqpp/pq-modifycommand.cpp @@ -15,11 +15,10 @@ PQ::ModifyCommand::ModifyCommand(Connection * conn, const std::string & sql, con unsigned int PQ::ModifyCommand::execute(bool anc) { - PGresult * res = PQexecPrepared( - c->conn, prepare(), static_cast(values.size()), values.data(), lengths.data(), formats.data(), 0); - c->checkResult(res, PGRES_COMMAND_OK, PGRES_TUPLES_OK); - auto rows = atoi(PQcmdTuples(res)); - PQclear(res); + const auto res = c->checkResult(PQexecPrepared(c->conn, prepare(), static_cast(values.size()), values.data(), + lengths.data(), formats.data(), 0), + PGRES_COMMAND_OK, PGRES_TUPLES_OK); + auto rows = atoi(PQcmdTuples(res.get())); if (rows == 0 && !anc) { throw DB::NoRowsAffected(); } -- cgit v1.2.3