#include "pq-bulkselectcommand.h" #include "command.h" #include "libpq-fe.h" #include "pq-command.h" #include "pq-connection.h" #include "pq-prepared.h" #include "pq-selectbase.h" #include 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) { } void PQ::BulkSelectCommand::execute() { if (!executed) { execRes = c->checkResult(PQexecPrepared(c->conn, prepare(), static_cast(values.size()), values.data(), lengths.data(), formats.data(), binary), PGRES_TUPLES_OK); nTuples = static_cast(PQntuples(execRes)); tuple = static_cast(-1); createColumns(execRes); executed = true; } } bool PQ::BulkSelectCommand::fetch() { execute(); if (++tuple < nTuples) { return true; } else { PQclear(execRes); execRes = nullptr; executed = false; return false; } }