diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-10-08 16:58:13 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-10-08 16:58:13 +0100 |
commit | 78d8eeadcf6642eb52b3b178d6da620b0bb34289 (patch) | |
tree | 4777a94e6438b79e146754c58ad81a7b6d2a4118 /libpqpp/pq-bulkselectcommand.cpp | |
parent | Fix virtual/override attribute use (diff) | |
download | libdbpp-postgresql-78d8eeadcf6642eb52b3b178d6da620b0bb34289.tar.bz2 libdbpp-postgresql-78d8eeadcf6642eb52b3b178d6da620b0bb34289.tar.xz libdbpp-postgresql-78d8eeadcf6642eb52b3b178d6da620b0bb34289.zip |
Use unique_ptr for execution results
Diffstat (limited to 'libpqpp/pq-bulkselectcommand.cpp')
-rw-r--r-- | libpqpp/pq-bulkselectcommand.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/libpqpp/pq-bulkselectcommand.cpp b/libpqpp/pq-bulkselectcommand.cpp index 298261e..303ed53 100644 --- a/libpqpp/pq-bulkselectcommand.cpp +++ b/libpqpp/pq-bulkselectcommand.cpp @@ -10,21 +10,20 @@ PQ::BulkSelectCommand::BulkSelectCommand(Connection * conn, const std::string & sql, const PQ::CommandOptionsCPtr & pqco, const DB::CommandOptionsCPtr & opts) : DB::Command(sql), - PQ::SelectBase(sql, pqco), PQ::PreparedStatement(conn, sql, opts), executed(false) + PQ::SelectBase(sql, pqco), PQ::PreparedStatement(conn, sql, opts) { } void PQ::BulkSelectCommand::execute() { - if (!executed) { + if (!execRes) { execRes = c->checkResult(PQexecPrepared(c->conn, prepare(), static_cast<int>(values.size()), values.data(), lengths.data(), formats.data(), binary), PGRES_TUPLES_OK); - nTuples = static_cast<decltype(nTuples)>(PQntuples(execRes)); + nTuples = static_cast<decltype(nTuples)>(PQntuples(execRes.get())); tuple = static_cast<decltype(tuple)>(-1); - createColumns(execRes); - executed = true; + createColumns(); } } @@ -36,9 +35,7 @@ PQ::BulkSelectCommand::fetch() return true; } else { - PQclear(execRes); - execRes = nullptr; - executed = false; + execRes.reset(); return false; } } |