summaryrefslogtreecommitdiff
path: root/libpqpp/pq-modifycommand.cpp
blob: 53c3231a799fd4237bd6cc447e3253eb4e922032 (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
#include "pq-modifycommand.h"
#include "command.h"
#include "modifycommand.h"
#include "pq-connection.h"
#include "pq-prepared.h"
#include <cstdlib>
#include <libpq-fe.h>
#include <vector>

PQ::ModifyCommand::ModifyCommand(Connection * conn, const std::string & sql, const DB::CommandOptionsCPtr & opts) :
	DB::Command(sql), DB::ModifyCommand(sql), PQ::PreparedStatement(conn, sql, opts)
{
}

unsigned int
PQ::ModifyCommand::execute(bool anc)
{
	const auto res = c->checkResult(PQexecPrepared(c->conn, prepare(), static_cast<int>(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();
	}
	return static_cast<unsigned int>(rows);
}