summaryrefslogtreecommitdiff
path: root/server/src/pracrodaopgsql.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/pracrodaopgsql.cc')
-rw-r--r--server/src/pracrodaopgsql.cc81
1 files changed, 40 insertions, 41 deletions
diff --git a/server/src/pracrodaopgsql.cc b/server/src/pracrodaopgsql.cc
index 6d7afe8..ee544df 100644
--- a/server/src/pracrodaopgsql.cc
+++ b/server/src/pracrodaopgsql.cc
@@ -65,16 +65,16 @@ PracroDAOPgsql::PracroDAOPgsql(std::string _host, std::string _port,
std::string ts;
try {
ts = "BEGIN;";
- PRACRO_DEBUG(sql, "Query: %s\n", ts.c_str());
+ DEBUG(sql, "Query: %s\n", ts.c_str());
pqxx::result R = W->exec(ts);
} catch(...) {
}
} catch(std::exception &e) {
- PRACRO_ERR_LOG(db, "Postgresql init failed: %s\n", e.what());
+ ERR_LOG(db, "Postgresql init failed: %s\n", e.what());
conn = NULL;
}
- PRACRO_DEBUG(db, "Pgsql connection %p (%s)\n", conn, cs.c_str());
+ DEBUG(db, "Pgsql connection %p (%s)\n", conn, cs.c_str());
}
PracroDAOPgsql::~PracroDAOPgsql()
@@ -91,12 +91,12 @@ void PracroDAOPgsql::commitTransaction(std::string user,
Fields &fields,
time_t now)
{
- PRACRO_DEBUG(db, "(%s, %s, %s, <%u fields>, %ld)\n",
- user.c_str(), patientid.c_str(),
- _macro.attributes["name"].c_str(),
- fields.size(), now);
-
- if(!conn) PRACRO_DEBUG(db, "No pgsql connection\n");
+ DEBUG(db, "(%s, %s, %s, <%u fields>, %ld)\n",
+ user.c_str(), patientid.c_str(),
+ _macro.attributes["name"].c_str(),
+ fields.size(), now);
+
+ if(!conn) DEBUG(db, "No pgsql connection\n");
if(fields.size() == 0) return;
std::string version = _macro.attributes["version"];
@@ -115,7 +115,7 @@ void PracroDAOPgsql::commitTransaction(std::string user,
" '" + W->esc(user) + "' "
");"
;
- PRACRO_DEBUG(sql, "Query: %s\n", ts.c_str());
+ DEBUG(sql, "Query: %s\n", ts.c_str());
pqxx::result R = W->exec(ts);
statements += ts + "\n";
@@ -130,19 +130,19 @@ void PracroDAOPgsql::commitTransaction(std::string user,
i++;
}
ts += ");";
- PRACRO_DEBUG(sql, "Query: %s\n", ts.c_str());
+ DEBUG(sql, "Query: %s\n", ts.c_str());
R = W->exec(ts);
// statements += ts + "\n";
- PRACRO_DEBUG(db, "input fields: %d, output fields: %lu\n",
- fields.size(), R.size());
+ DEBUG(db, "input fields: %d, output fields: %lu\n",
+ fields.size(), R.size());
// Store known fields
pqxx::result::const_iterator ri = R.begin();
if(ri != R.end()) {
std::string name = (*ri)[0].c_str();
- PRACRO_DEBUG(db, "Storing: %s with value %s\n",
- name.c_str(), fields[name].c_str());
+ DEBUG(db, "Storing: %s with value %s\n",
+ name.c_str(), fields[name].c_str());
ts = "INSERT INTO fields (transaction, name, value) "
"VALUES ( currval('trseq'), '" + W->esc(name) + "', '" +
W->esc(fields[name]) + "')";
@@ -150,15 +150,15 @@ void PracroDAOPgsql::commitTransaction(std::string user,
while(ri != R.end()) {
name = (*ri)[0].c_str();
- PRACRO_DEBUG(db, "Storing: %s with value %s\n",
- name.c_str(), fields[name].c_str());
+ DEBUG(db, "Storing: %s with value %s\n",
+ name.c_str(), fields[name].c_str());
ts += ", (currval('trseq'), '" + W->esc(name) + "', '" +
W->esc(fields[name]) + "')";
ri++;
}
ts += ";";
- PRACRO_DEBUG(sql, "Query: %s\n", ts.c_str());
+ DEBUG(sql, "Query: %s\n", ts.c_str());
W->exec(ts);
statements += ts + "\n";
@@ -166,7 +166,7 @@ void PracroDAOPgsql::commitTransaction(std::string user,
}
// W->commit();
} catch(std::exception &e) {
- PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
+ ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
}
}
@@ -197,11 +197,11 @@ Values PracroDAOPgsql::getLatestValues(std::string patientid,
Fieldnames &fieldnames,
time_t oldest)
{
- PRACRO_DEBUG(db, "(%s, %s, <%u fieldnames>, %ld)\n",
- patientid.c_str(),
- macro ? macro->attributes["name"].c_str() : "(null)",
- fieldnames.size(), oldest);
- if(!conn) PRACRO_DEBUG(db, "No pgsql connection\n");
+ DEBUG(db, "(%s, %s, <%u fieldnames>, %ld)\n",
+ patientid.c_str(),
+ macro ? macro->attributes["name"].c_str() : "(null)",
+ fieldnames.size(), oldest);
+ if(!conn) DEBUG(db, "No pgsql connection\n");
Values values;
std::string query;
@@ -244,7 +244,7 @@ Values PracroDAOPgsql::getLatestValues(std::string patientid,
query += " AND tt.version = '" + macro->attributes["version"] + "'";
}
- PRACRO_DEBUG(sql, "Query: %s\n", query.c_str());
+ DEBUG(sql, "Query: %s\n", query.c_str());
pqxx::result R = W->exec(query);
pqxx::result::const_iterator ri = R.begin();
while(ri != R.end()) {
@@ -255,7 +255,7 @@ Values PracroDAOPgsql::getLatestValues(std::string patientid,
ri++;
}
} catch (std::exception &e) {
- PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str());
+ ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str());
}
return values;
@@ -274,18 +274,18 @@ unsigned PracroDAOPgsql::nrOfCommits(std::string patientid,
" AND macro = '" + W->esc(macroname) + "' "
" AND timestamp >= " + soldest.str()
;
- PRACRO_DEBUG(sql, "Query: %s\n", query.c_str());
+ DEBUG(sql, "Query: %s\n", query.c_str());
pqxx::result R = W->exec(query);
if(R.size() != 1) {
- PRACRO_ERR_LOG(db, "No result set; expected one row with one column\n");
+ ERR_LOG(db, "No result set; expected one row with one column\n");
return 0;
}
unsigned n = (unsigned)atol((*R.begin())[0].c_str());
- PRACRO_DEBUG(db, "Found %u commits for %s(%s) from %ld\n",
+ DEBUG(db, "Found %u commits for %s(%s) from %ld\n",
n, patientid.c_str(), macroname.c_str(), oldest);
return n;
} catch (std::exception &e) {
- PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str());
+ ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str());
}
return 0;
@@ -302,11 +302,11 @@ void PracroDAOPgsql::addFieldname(std::string name, std::string description)
" '" + W->esc(timestamp.str()) + "' "
")"
;
- PRACRO_DEBUG(sql, "Query: %s\n", ts.c_str());
+ DEBUG(sql, "Query: %s\n", ts.c_str());
pqxx::result R = W->exec(ts);
W->commit();
} catch (std::exception &e) {
- PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
+ ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
}
}
@@ -316,23 +316,23 @@ void PracroDAOPgsql::delFieldname(std::string name)
try {
ts = "DELETE FROM fieldnames WHERE name="
"'" + W->esc(name) + "' ";
- PRACRO_DEBUG(sql, "Query: %s\n", ts.c_str());
+ DEBUG(sql, "Query: %s\n", ts.c_str());
pqxx::result R = W->exec(ts);
W->commit();
} catch (std::exception &e) {
- PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
+ ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str());
}
}
std::vector<Fieldname> PracroDAOPgsql::getFieldnames()
{
- if(!conn) PRACRO_DEBUG(db, "No pgsql connection\n");
+ if(!conn) DEBUG(db, "No pgsql connection\n");
std::vector<Fieldname> fieldnames;
std::string query;
try {
query = "SELECT * FROM fieldnames";
- PRACRO_DEBUG(sql, "Query: %s\n", query.c_str());
+ DEBUG(sql, "Query: %s\n", query.c_str());
pqxx::result R = W->exec(query);
pqxx::result::const_iterator ri = R.begin();
while(ri != R.end()) {
@@ -344,7 +344,7 @@ std::vector<Fieldname> PracroDAOPgsql::getFieldnames()
ri++;
}
} catch (std::exception &e) {
- PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str());
+ ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str());
}
return fieldnames;
@@ -357,7 +357,7 @@ void PracroDAOPgsql::commit()
W->commit();
statements = "";
} catch (std::exception &e) {
- PRACRO_ERR_LOG(db, "Commit failed: %s: %s\n", e.what(), ts.c_str());
+ ERR_LOG(db, "Commit failed: %s: %s\n", e.what(), ts.c_str());
}
}
@@ -368,8 +368,7 @@ void PracroDAOPgsql::discard()
W->abort();
statements = "";
} catch (std::exception &e) {
- PRACRO_ERR_LOG(db, "Abort (rollback) failed: %s: %s\n",
- e.what(), ts.c_str());
+ ERR_LOG(db, "Abort (rollback) failed: %s: %s\n", e.what(), ts.c_str());
}
}
@@ -382,7 +381,7 @@ void PracroDAOPgsql::restore(const std::string &data)
{
std::string ts;
try {
- PRACRO_DEBUG(sql, "Restore: %s\n", data.c_str());
+ DEBUG(sql, "Restore: %s\n", data.c_str());
pqxx::result R = W->exec(data);
statements = data;
} catch( ... ) {