summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-02-26 14:57:37 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2014-02-26 14:57:37 +0100
commit070d2c7d55af1cac5f1c7b55186cb7cb3f69dab1 (patch)
tree6541607aea0154fa1a02e37423928d926a364da1
parentd2715d7c3534f35de0ebdd30d8d770bd79ca7a23 (diff)
Port from libpqxx to libpq.
-rw-r--r--server/configure.in9
-rw-r--r--server/src/Makefile.am6
-rw-r--r--server/src/admin_export.cc77
-rw-r--r--server/src/pgwork.cc146
-rw-r--r--server/src/pgwork.h65
-rw-r--r--server/src/pracrodaopgsql.cc104
-rw-r--r--server/src/pracrodaopgsql.h4
7 files changed, 330 insertions, 81 deletions
diff --git a/server/configure.in b/server/configure.in
index e65ac33..3b6d593 100644
--- a/server/configure.in
+++ b/server/configure.in
@@ -93,11 +93,12 @@ if test x$with_db == xno; then
AC_DEFINE_UNQUOTED(WITHOUT_DB, , [The project is configured not to use the db])
else
dnl ======================
- dnl Check for libpqxx
+ dnl Check for libpg
dnl ======================
- PKG_CHECK_MODULES(PQXX, libpqxx >= 4.0,
- [AC_DEFINE_UNQUOTED([USE_NEW_PQXX], [1], [Use new pqx api])],
- [PKG_CHECK_MODULES(PQXX, libpqxx >= 2.6.8)] )
+ PQ_CFLAGS="-I$(pg_config --includedir)"
+ AC_SUBST(PQ_CFLAGS)
+ PQ_LIBS="-L$(pg_config --libdir) -lpq"
+ AC_SUBST(PQ_LIBS)
fi
dnl ======================
diff --git a/server/src/Makefile.am b/server/src/Makefile.am
index c852eb0..855bec2 100644
--- a/server/src/Makefile.am
+++ b/server/src/Makefile.am
@@ -2,11 +2,11 @@ SUBDIRS =
bin_PROGRAMS = pracrod
-pracrod_LDADD = $(LD_EFENCE) $(PQXX_LIBS) $(CONFIG_LIBS) \
+pracrod_LDADD = $(LD_EFENCE) $(PQ_LIBS) $(CONFIG_LIBS) \
$(LUA_LIBS) $(HTTPD_LIBS) $(PTHREAD_LIBS) \
$(EXPAT_LIBS) $(ATF_LIBS) $(CURL_LIBS)
-pracrod_CXXFLAGS = $(PQXX_CXXFLAGS) $(CONFIG_CXXFLAGS) \
+pracrod_CXXFLAGS = $(PQ_CFLAGS) $(CONFIG_CXXFLAGS) \
$(LUA_CFLAGS) $(HTTPD_CFLAGS) $(EXPAT_CFLAGS) \
$(PTHREAD_CFLAGS) $(ATF_CFLAGS) $(CURL_CFLAGS)
@@ -46,6 +46,7 @@ pracrod_SOURCES = \
macrolist.cc \
macroparser.cc \
mutex.cc \
+ pgwork.cc \
pracrodao.cc \
pracrodaopgsql.cc \
pracrodaotest.cc \
@@ -109,6 +110,7 @@ EXTRA_DIST = \
macrolist.h \
macroparser.h \
mutex.h \
+ pgwork.h \
pracrodao.h \
pracrodaopgsql.h \
pracrodaotest.h \
diff --git a/server/src/admin_export.cc b/server/src/admin_export.cc
index 3bdfcf6..6f5ecba 100644
--- a/server/src/admin_export.cc
+++ b/server/src/admin_export.cc
@@ -34,20 +34,14 @@
#ifndef WITHOUT_DB
#include <stdlib.h>
-#include <pqxx/pqxx>
+
+#include "pgwork.h"
#include "fieldnamescanner.h"
#include "configuration.h"
#define SEP "\t"
-#ifdef USE_NEW_PQXX
-#include <pqxx/tuple.hxx>
-typedef pqxx::tuple tuple_t;
-#else
-typedef pqxx::result::tuple tuple_t;
-#endif
-
static std::string escape(std::string &str)
{
std::string out = "\"";
@@ -65,7 +59,7 @@ static std::string escape(std::string &str)
class File {
public:
- File(fieldnames_t &f, pqxx::work &w)
+ File(fieldnames_t &f, Work &w)
: work(w), fieldnames(f)
{
pos["id"] = 0;
@@ -93,16 +87,26 @@ public:
addcell("template", "Template");
{
- pqxx::result result =
+ result_t result =
work.exec("SELECT DISTINCT ON(name) name, caption FROM fieldnames"
" WHERE extract='true';");
- pqxx::result::const_iterator ri = result.begin();
+ result_t::const_iterator ri = result.begin();
+ /*
for(unsigned int r = 0; r < result.size(); r++) {
tuple_t tuple = result.at(r);
std::string name = tuple.at(0).c_str();
std::string caption = tuple.at(1).c_str();
addcell(name, caption);
}
+ */
+ while(ri != result.end()) {
+ tuple_t tuple = *ri;
+ std::string name = tuple.at(0).c_str();
+ std::string caption = tuple.at(1).c_str();
+ addcell(name, caption);
+ ri++;
+ }
+
}
endrow();
@@ -133,7 +137,7 @@ public:
std::string result;
private:
- pqxx::work &work;
+ Work &work;
std::map<std::string, int> pos;
std::vector<std::string> cells;
std::string name;
@@ -162,22 +166,39 @@ static std::string do_export(Environment &env, std::string templ, bool *ok,
if(passwd.size()) cs += " password=" + passwd;
cs += " dbname=" + (dbname.size() ? dbname : "pracro");
- pqxx::connection conn(cs);
- pqxx::work work(conn);
+ // pqxx::connection conn(cs);
+ PGconn *conn = PQconnectdb(cs.c_str());
+
+ if(conn == NULL || PQstatus(conn) == CONNECTION_BAD) {
+ ERR(db, "Postgresql init failed: %s\n", PQerrorMessage(conn));
+ conn = NULL;
+ return "Postgresql init failed";
+ }
+
+ Work work(conn);
std::set<std::string> filter;
{
- pqxx::result result =
+ result_t result =
work.exec("SELECT DISTINCT name FROM fieldnames"
" WHERE extract='true';");
- pqxx::result::const_iterator ri = result.begin();
+ result_t::const_iterator ri = result.begin();
+ /*
for(unsigned int r = 0; r < result.size(); r++) {
tuple_t tuple = result.at(r);
std::string name = tuple.at(0).c_str();
filter.insert(name);
//printf("filter: '%s'\n", name.c_str());
}
+ */
+ while(ri != result.end()) {
+ tuple_t tuple = *ri;
+ std::string name = tuple.at(0).c_str();
+ filter.insert(name);
+ //printf("filter: '%s'\n", name.c_str());
+ ri++;
+ }
}
templates_t t = scanfieldnames(env, filter);
@@ -213,10 +234,11 @@ static std::string do_export(Environment &env, std::string templ, bool *ok,
DEBUG(export, "QUERY: %s\n", q.c_str());
- pqxx::result result = work.exec(q);
- pqxx::result::const_iterator ri = result.begin();
- for(unsigned int r = 0; r < result.size(); r++) {
- tuple_t tuple = result.at(r);
+ result_t result = work.exec(q);
+ result_t::const_iterator ri = result.begin();
+ // for(unsigned int r = 0; r < result.size(); r++) {
+ while(ri != result.end()) {
+ tuple_t tuple = *ri;
std::string patientid = tuple.at(0).c_str();
std::string templ = tuple.at(1).c_str();
std::string version = tuple.at(2).c_str();
@@ -238,15 +260,16 @@ static std::string do_export(Environment &env, std::string templ, bool *ok,
timestamp.c_str(), patientid.c_str(), templ.c_str());
{
- pqxx::result result =
+ result_t result =
work.exec("SELECT f.name, f.value"
" FROM transactions t, fields f, fieldnames n"
" WHERE t.cid='"+uid+"' AND f.transaction=t.uid"
" AND f.name=n.name AND n.extract='true'"
" ORDER BY t.timestamp;");
- pqxx::result::const_iterator ri = result.begin();
- for(unsigned int r = 0; r < result.size(); r++) {
- tuple_t tuple = result.at(r);
+ result_t::const_iterator ri = result.begin();
+ //for(unsigned int r = 0; r < result.size(); r++) {
+ while(ri != result.end()) {
+ tuple_t tuple = *ri;
std::string name = tuple.at(0).c_str();
std::string value = tuple.at(1).c_str();
@@ -256,10 +279,16 @@ static std::string do_export(Environment &env, std::string templ, bool *ok,
}
file.endrow();
+ ri++;
}
}
*ok = true;
+
+ // Make sure we stop using the connection before we close the connection.
+ work.abort();
+ PQfinish(conn);
+
return file.result;
}
diff --git a/server/src/pgwork.cc b/server/src/pgwork.cc
new file mode 100644
index 0000000..948bb5f
--- /dev/null
+++ b/server/src/pgwork.cc
@@ -0,0 +1,146 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * pgwork.cc
+ *
+ * Wed Feb 26 14:49:37 CET 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "pgwork.h"
+
+#include <stdlib.h>
+
+#include "debug.h"
+
+/**
+ * Convert list of tuples to list of string arrays.
+ */
+static result_t toArray(PGresult *pg)
+{
+ std::list<std::vector<std::string> > res;
+ for(int j = 0; j < PQntuples(pg); j++) {
+ std::vector<std::string> v;
+ for(int i = 0; i < PQnfields(pg); i++) {
+ v.push_back(std::string(PQgetvalue(pg, j, i)));
+ }
+ res.push_back(v);
+ }
+ return res;
+}
+
+class pq_exc : public std::exception {
+public:
+ pq_exc(std::string _what) : w(_what) {}
+ ~pq_exc() throw() {}
+ const char *what() { return w.c_str(); }
+private:
+ std::string w;
+};
+
+Work::Work(PGconn *_c) throw(std::exception)
+ : c(_c)
+{
+ state = WORK_OPEN;
+ try {
+ exec("BEGIN");
+ } catch(std::exception &e) {
+ ERR(db, "Error beginning transaction: %s\n", e.what());
+ state = WORK_INVALID;
+ throw e;
+ }
+}
+
+Work::~Work()
+{
+ if(state == WORK_OPEN) abort();
+}
+
+/**
+ * Execute query and return result as list of string arrays.
+ */
+result_t Work::exec(const std::string &query)
+ throw(std::exception)
+{
+ if(state != WORK_OPEN) {
+ ERR(db, "Transaction is not is not valid. Cannot execute query!\n");
+ return result_t();
+ }
+
+ PGresult *pg = PQexec(c, query.c_str());
+ if(PQresultStatus(pg) != PGRES_TUPLES_OK &&
+ PQresultStatus(pg) != PGRES_COMMAND_OK) {
+ throw pq_exc(PQerrorMessage(c));
+ }
+
+ result_t R = toArray(pg);
+
+ PQclear(pg);
+ return R;
+}
+
+void Work::commit()
+ throw(std::exception)
+{
+ try {
+ exec("COMMIT");
+ } catch(std::exception &e) {
+ ERR(db, "Error committing transaction: %s\n", e.what());
+ throw e;
+ }
+ state = WORK_COMMITTED;
+}
+
+void Work::abort()
+ throw(std::exception)
+{
+ try {
+ exec("ROLLBACK");
+ } catch(std::exception &e) {
+ ERR(db, "Error aborting transaction: %s\n", e.what());
+ throw e;
+ }
+ state = WORK_ABORTED;
+}
+
+std::string Work::esc(const std::string &from)
+{
+ if(from == "") return "";
+
+ size_t buf_size = from.length() * 2 + 1;
+ char *buf = (char *)malloc(buf_size);
+ int error = 0;
+
+ size_t size = PQescapeStringConn(c, buf, from.data(),
+ from.length(), &error);
+
+ if(error) {
+ ERR(db, "SQL escaping failed due to invalid multibyte character"
+ " in '%s'\n", from.c_str());
+ return "";
+ }
+
+ std::string to;
+ if(size > 0 && error == 0) to.append(buf, size);
+
+ free(buf);
+ return to;
+}
diff --git a/server/src/pgwork.h b/server/src/pgwork.h
new file mode 100644
index 0000000..6b52559
--- /dev/null
+++ b/server/src/pgwork.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * pgwork.h
+ *
+ * Wed Feb 26 14:49:37 CET 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_PGWORK_H__
+#define __PRACRO_PGWORK_H__
+
+#ifndef WITHOUT_DB
+
+#include <list>
+#include <vector>
+#include <string>
+
+#include <libpq-fe.h>
+
+typedef std::list<std::vector<std::string> > result_t;
+typedef std::vector<std::string> tuple_t;
+
+class Work {
+public:
+ typedef enum {
+ WORK_INVALID,
+ WORK_OPEN,
+ WORK_COMMITTED,
+ WORK_ABORTED
+ } work_state_t;
+
+ Work(PGconn *_c) throw(std::exception);
+ ~Work();
+ result_t exec(const std::string &query) throw(std::exception);
+ void commit() throw(std::exception);
+ void abort() throw(std::exception);
+ std::string esc(const std::string &from);
+
+private:
+ PGconn *c;
+ work_state_t state;
+};
+
+#endif/*WITHOUT_DB*/
+
+#endif/*__PRACRO_PGWORK_H__*/
diff --git a/server/src/pracrodaopgsql.cc b/server/src/pracrodaopgsql.cc
index 3c7040a..2192031 100644
--- a/server/src/pracrodaopgsql.cc
+++ b/server/src/pracrodaopgsql.cc
@@ -43,9 +43,13 @@
#ifndef WITHOUT_DB
#include <stdlib.h>
+#include <list>
+#include <sstream>
#include "debug.h"
+#include "pgwork.h"
+
PracroDAOPgsql::PracroDAOPgsql(std::string _host, std::string _port,
std::string _user, std::string _passwd,
std::string _dbname)
@@ -58,11 +62,13 @@ PracroDAOPgsql::PracroDAOPgsql(std::string _host, std::string _port,
if(user.size()) cs += " user=" + user;
if(passwd.size()) cs += " password=" + passwd;
cs += " dbname=" + (dbname.size() ? dbname : "pracro");
- try {
- conn = new pqxx::connection(cs);
- } catch(std::exception &e) {
- ERR_LOG(db, "Postgresql init failed: %s\n", e.what());
+
+ conn = PQconnectdb(cs.c_str());
+
+ if(conn == NULL || PQstatus(conn) == CONNECTION_BAD) {
+ ERR_LOG(db, "Postgresql init failed: %s\n", PQerrorMessage(conn));
conn = NULL;
+ return;
}
DEBUG(db, "Pgsql connection %p (%s)\n", conn, cs.c_str());
@@ -71,7 +77,7 @@ PracroDAOPgsql::PracroDAOPgsql(std::string _host, std::string _port,
PracroDAOPgsql::~PracroDAOPgsql()
{
if(conn) {
- delete conn;
+ PQfinish(conn);
}
}
@@ -83,9 +89,9 @@ std::string PracroDAOPgsql::newSessionId()
}
try {
- pqxx::work W(*conn);
- pqxx::result R = W.exec("SELECT nextval('sessionseq');");
- pqxx::result::const_iterator ri = R.begin();
+ Work W(conn);
+ result_t R = W.exec("SELECT nextval('sessionseq');");
+ result_t::const_iterator ri = R.begin();
if(ri != R.end()) {
DEBUG(db, "New session id: %s\n", (*ri)[0].c_str());
return (*ri)[0].c_str();
@@ -118,7 +124,7 @@ void PracroDAOPgsql::commitTransaction(std::string sessionid,
if(commit.fields.size() == 0) return;
- pqxx::work W(*conn);
+ Work W(conn);
std::string version = _macro.version;
std::string macro = _macro.name;
@@ -128,7 +134,7 @@ void PracroDAOPgsql::commitTransaction(std::string sessionid,
try {
ts = "SELECT status FROM commits WHERE uid='"+sessionid+"';";
- pqxx::result R = W.exec(ts);
+ result_t R = W.exec(ts);
if(!R.size()) {
ts = "INSERT INTO commits (patientid, template, version,"
" \"timestamp\", uid, status) VALUES ("
@@ -141,10 +147,10 @@ void PracroDAOPgsql::commitTransaction(std::string sessionid,
");"
;
DEBUG(sql, "Query: %s\n", ts.c_str());
- pqxx::result R = W.exec(ts);
+ result_t R = W.exec(ts);
} else {
- pqxx::result::const_iterator ri = R.begin();
+ result_t::const_iterator ri = R.begin();
if(ri != R.end()) {
std::string status = (*ri)[0].c_str();
if(status == "committed") {
@@ -156,7 +162,7 @@ void PracroDAOPgsql::commitTransaction(std::string sessionid,
ts = "UPDATE commits SET status='active' WHERE uid="+sessionid+";";
DEBUG(sql, "Query: %s\n", ts.c_str());
- /*pqxx::result R = */W.exec(ts);
+ /*result_t R = */W.exec(ts);
}
} catch(std::exception &e) {
ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
@@ -175,7 +181,7 @@ void PracroDAOPgsql::commitTransaction(std::string sessionid,
");"
;
DEBUG(sql, "Query: %s\n", ts.c_str());
- pqxx::result R = W.exec(ts);
+ result_t R = W.exec(ts);
if(commit.fields.size() > 0) {
// field table lookup
@@ -191,11 +197,11 @@ void PracroDAOPgsql::commitTransaction(std::string sessionid,
DEBUG(sql, "Query: %s\n", ts.c_str());
R = W.exec(ts);
- DEBUG(db, "input fields: %d, output fields: %lu\n",
- commit.fields.size(), R.size());
+ DEBUG(db, "input fields: %d, output fields: %d\n",
+ commit.fields.size(), (int)R.size());
// Store known fields
- pqxx::result::const_iterator ri = R.begin();
+ result_t::const_iterator ri = R.begin();
if(ri != R.end()) {
std::string name = (*ri)[0].c_str();
DEBUG(db, "Storing: %s with value %s\n",
@@ -253,15 +259,15 @@ Values PracroDAOPgsql::getLatestValues(std::string sessionid,
std::stringstream soldest; soldest << oldest;
try {
{
- pqxx::work W(*conn);
+ Work W(conn);
query = "UPDATE commits SET status='active' WHERE status='idle'"
" AND uid="+sessionid+";";
DEBUG(sql, "Query: %s\n", query.c_str());
- /*pqxx::result R = */W.exec(query);
+ /*result_t R = */W.exec(query);
W.commit();
}
- pqxx::work W(*conn);
+ Work W(conn);
#ifdef NEW
@@ -288,16 +294,16 @@ Values PracroDAOPgsql::getLatestValues(std::string sessionid,
" \"timestamp\">="+soldest.str()+" AND"
" (status='committed' OR uid="+sessionid+");";
DEBUG(sql, "Query: %s\n", query.c_str());
- pqxx::result commits = W.exec(query);
- pqxx::result::const_iterator ci = commits.begin();
+ result_t commits = W.exec(query);
+ result_t::const_iterator ci = commits.begin();
while(ci != commits.end()) {
std::string cid = (*ci)[0].c_str();
query = "SELECT uid, \"timestamp\" FROM transactions WHERE cid="+cid+
macros+";";
DEBUG(sql, "Query: %s\n", query.c_str());
- pqxx::result transactions = W.exec(query);
- pqxx::result::const_iterator ti = transactions.begin();
+ result_t transactions = W.exec(query);
+ result_t::const_iterator ti = transactions.begin();
while(ti != transactions.end()) {
std::string tid = (*ti)[0].c_str();
time_t timestamp = atol((*ti)[1].c_str());
@@ -305,9 +311,9 @@ Values PracroDAOPgsql::getLatestValues(std::string sessionid,
query = "SELECT name, value FROM fields WHERE"
" transaction="+tid+" AND ("+ names +");";
DEBUG(sql, "Query: %s\n", query.c_str());
- pqxx::result fields = W.exec(query);
+ result_t fields = W.exec(query);
DEBUG(sql, "Results: %lu\n", fields.size());
- pqxx::result::const_iterator fi = fields.begin();
+ result_t::const_iterator fi = fields.begin();
while(fi != fields.end()) {
std::string name = (*fi)[0].c_str();
if(values.find(name) == values.end() ||
@@ -374,8 +380,8 @@ Values PracroDAOPgsql::getLatestValues(std::string sessionid,
}
DEBUG(sql, "Query: %s\n", query.c_str());
- pqxx::result R = W.exec(query);
- pqxx::result::const_iterator ri = R.begin();
+ result_t R = W.exec(query);
+ result_t::const_iterator ri = R.begin();
while(ri != R.end()) {
Value v;
v.value = (*ri)[1].c_str();
@@ -407,7 +413,7 @@ unsigned PracroDAOPgsql::nrOfCommits(std::string sessionid,
std::string query;
std::stringstream soldest; soldest << oldest;
try {
- pqxx::work W(*conn);
+ Work W(conn);
query = "SELECT count(*) FROM commits c, transactions f"
" WHERE c.patientid = '" + W.esc(patientid) + "' AND c.uid = f.cid";
//if(!uncom) query += " AND (c.status='committed' OR c.uid="+sessionid+")";
@@ -416,7 +422,7 @@ unsigned PracroDAOPgsql::nrOfCommits(std::string sessionid,
//" AND f.timestamp >= " + soldest.str()
;
DEBUG(sql, "Query: %s\n", query.c_str());
- pqxx::result R = W.exec(query);
+ result_t R = W.exec(query);
if(R.size() != 1) {
ERR_LOG(db, "No result set; expected one row with one column\n");
return 0;
@@ -443,10 +449,10 @@ void PracroDAOPgsql::addFieldname(std::string name, std::string description)
std::string ts;
try {
- pqxx::work W(*conn);
+ Work W(conn);
ts = "SELECT name FROM fieldnames WHERE name='"+W.esc(name)+"';";
- pqxx::result Rc = W.exec(ts);
+ result_t Rc = W.exec(ts);
if(Rc.size()) {
ts = "UPDATE fieldnames SET "
" description='" + W.esc(description) + "', "
@@ -461,7 +467,7 @@ void PracroDAOPgsql::addFieldname(std::string name, std::string description)
;
}
DEBUG(sql, "Query: %s\n", ts.c_str());
- pqxx::result R = W.exec(ts);
+ result_t R = W.exec(ts);
W.commit();
} catch (std::exception &e) {
ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
@@ -477,11 +483,11 @@ void PracroDAOPgsql::delFieldname(std::string name)
std::string ts;
try {
- pqxx::work W(*conn);
+ Work W(conn);
ts = "DELETE FROM fieldnames WHERE name="
"'" + W.esc(name) + "' ";
DEBUG(sql, "Query: %s\n", ts.c_str());
- pqxx::result R = W.exec(ts);
+ result_t R = W.exec(ts);
W.commit();
} catch (std::exception &e) {
ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
@@ -499,11 +505,11 @@ std::vector<Fieldname> PracroDAOPgsql::getFieldnames()
std::string query;
try {
- pqxx::work W(*conn);
+ Work W(conn);
query = "SELECT * FROM fieldnames";
DEBUG(sql, "Query: %s\n", query.c_str());
- pqxx::result R = W.exec(query);
- pqxx::result::const_iterator ri = R.begin();
+ result_t R = W.exec(query);
+ result_t::const_iterator ri = R.begin();
while(ri != R.end()) {
Fieldname f;
f.name = (*ri)[0].c_str();
@@ -528,9 +534,9 @@ void PracroDAOPgsql::commit(std::string sessionid)
std::string ts;
try {
- pqxx::work W(*conn);
+ Work W(conn);
ts = "UPDATE commits SET status='committed' WHERE uid="+sessionid+";";
- /*pqxx::result R = */W.exec(ts);
+ /*result_t R = */W.exec(ts);
W.commit();
} catch (std::exception &e) {
@@ -547,9 +553,9 @@ void PracroDAOPgsql::nocommit(std::string sessionid)
std::string ts;
try {
- pqxx::work W(*conn);
+ Work W(conn);
ts = "UPDATE commits SET status='idle' WHERE uid="+sessionid+";";
- /*pqxx::result R = */W.exec(ts);
+ /*result_t R = */W.exec(ts);
W.commit();
} catch (std::exception &e) {
@@ -566,9 +572,9 @@ void PracroDAOPgsql::discard(std::string sessionid)
std::string ts;
try {
- pqxx::work W(*conn);
+ Work W(conn);
ts = "DELETE FROM commits WHERE uid="+sessionid+";";
- /*pqxx::result R = */W.exec(ts);
+ /*result_t R = */W.exec(ts);
W.commit();
} catch (std::exception &e) {
ERR_LOG(db, "Abort (rollback) failed: %s: %s\n", e.what(), ts.c_str());
@@ -584,9 +590,9 @@ bool PracroDAOPgsql::idle(std::string sessionid)
std::string ts = "SELECT status FROM commits WHERE uid='"+sessionid+"';";
try {
- pqxx::work W(*conn);
- pqxx::result R = W.exec(ts);
- pqxx::result::const_iterator ri = R.begin();
+ Work W(conn);
+ result_t R = W.exec(ts);
+ result_t::const_iterator ri = R.begin();
if(ri != R.end()) {
std::string status = (*ri)[0].c_str();
return status == "idle";
@@ -607,7 +613,7 @@ void PracroDAOPgsql::setIdle(std::string sessionid, bool idle)
std::string ts;
try {
- pqxx::work W(*conn);
+ Work W(conn);
if(idle) {
ts = "UPDATE commits SET status='idle' WHERE uid="+sessionid+
" AND status='active';";
@@ -615,7 +621,7 @@ void PracroDAOPgsql::setIdle(std::string sessionid, bool idle)
ts = "UPDATE commits SET status='active' WHERE uid="+sessionid+
" AND status='idle';";
}
- /*pqxx::result R = */W.exec(ts);
+ /*result_t R = */W.exec(ts);
W.commit();
} catch (std::exception &e) {
diff --git a/server/src/pracrodaopgsql.h b/server/src/pracrodaopgsql.h
index e21d39c..13fa019 100644
--- a/server/src/pracrodaopgsql.h
+++ b/server/src/pracrodaopgsql.h
@@ -33,7 +33,7 @@
#ifndef WITHOUT_DB
#include <string>
-#include <pqxx/pqxx>
+#include <libpq-fe.h>
#include "pracrodao.h"
@@ -75,7 +75,7 @@ public:
void setIdle(std::string sessionid, bool idle);
private:
- pqxx::connection *conn;
+ PGconn *conn;
};
#endif/*WITHOUT_DB*/