summaryrefslogtreecommitdiff
path: root/libpqpp/pq-modifycommand.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-24 04:00:01 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-24 04:00:01 +0000
commitb177499d168936da9e64a964beb22f6057880703 (patch)
treec093da732b44e713af9fad35ff70539455cc355a /libpqpp/pq-modifycommand.cpp
parentUse parent glibmm (diff)
downloadlibdbpp-postgresql-b177499d168936da9e64a964beb22f6057880703.tar.bz2
libdbpp-postgresql-b177499d168936da9e64a964beb22f6057880703.tar.xz
libdbpp-postgresql-b177499d168936da9e64a964beb22f6057880703.zip
PostgreSQL files prefixed with pq-
Diffstat (limited to 'libpqpp/pq-modifycommand.cpp')
-rw-r--r--libpqpp/pq-modifycommand.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/libpqpp/pq-modifycommand.cpp b/libpqpp/pq-modifycommand.cpp
new file mode 100644
index 0000000..e07af0b
--- /dev/null
+++ b/libpqpp/pq-modifycommand.cpp
@@ -0,0 +1,44 @@
+#include "pq-modifycommand.h"
+#include "pq-error.h"
+#include <stdlib.h>
+#include "pq-connection.h"
+
+PQ::ModifyCommand::ModifyCommand(const Connection * conn, const std::string & sql, unsigned int no) :
+ DB::Command(sql),
+ DB::ModifyCommand(sql),
+ PQ::Command(conn, sql, no),
+ prepared(false)
+{
+}
+
+PQ::ModifyCommand::~ModifyCommand()
+{
+}
+
+void
+PQ::ModifyCommand::prepare() const
+{
+ if (!prepared) {
+ std::string psql;
+ psql.reserve(sql.length() + 20);
+ prepareSql(psql, sql);
+ c->checkResultFree(PQprepare(
+ c->conn, stmntName.c_str(), psql.c_str(), values.size(), NULL), PGRES_COMMAND_OK);
+ prepared = true;
+ }
+}
+
+unsigned int
+PQ::ModifyCommand::execute(bool anc)
+{
+ prepare();
+ PGresult * res = PQexecPrepared(c->conn, stmntName.c_str(), values.size(), &values.front(), &lengths.front(), &formats.front(), 0);
+ c->checkResult(res, PGRES_COMMAND_OK, PGRES_TUPLES_OK);
+ unsigned int rows = atoi(PQcmdTuples(res));
+ PQclear(res);
+ if (rows == 0 && !anc) {
+ throw Error("No rows affected");
+ }
+ return rows;
+}
+