summaryrefslogtreecommitdiff
path: root/libpqpp/pq-bulkselectcommand.cpp
blob: 303ed5385c8b5e2fd01c56427cf9f41cfdd0be94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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 <vector>

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)
{
}

void
PQ::BulkSelectCommand::execute()
{
	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.get()));
		tuple = static_cast<decltype(tuple)>(-1);
		createColumns();
	}
}

bool
PQ::BulkSelectCommand::fetch()
{
	execute();
	if (++tuple < nTuples) {
		return true;
	}
	else {
		execRes.reset();
		return false;
	}
}