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
42
|
#include "pq-bulkselectcommand.h"
#include "pq-connection.h"
#include "pq-column.h"
#include "pq-error.h"
PQ::BulkSelectCommand::BulkSelectCommand(Connection * conn, const std::string & sql, unsigned int no, const DB::CommandOptions * opts) :
DB::Command(sql),
PQ::SelectBase(sql),
PQ::PreparedStatement(conn, sql, no, opts),
executed(false)
{
}
void
PQ::BulkSelectCommand::execute()
{
if (!executed) {
execRes = c->checkResult(
PQexecPrepared(c->conn, prepare(), values.size(), &values.front(), &lengths.front(), NULL, 0),
PGRES_TUPLES_OK);
nTuples = PQntuples(execRes);
tuple = -1;
createColumns(execRes);
executed = true;
}
}
bool
PQ::BulkSelectCommand::fetch()
{
execute();
if (++tuple < nTuples) {
return true;
}
else {
PQclear(execRes);
execRes = NULL;
executed = false;
return false;
}
}
|