From 7a8185affa101ba8239a310321a3524eb3e6f650 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 14 Jan 2011 10:23:38 +0000 Subject: Add 'template' to transactions table in db. --- server/src/database.h | 9 ++++----- server/src/pracrodao.h | 5 ++--- server/src/pracrodaopgsql.cc | 34 +++++++++++++++++----------------- server/src/pracrodaopgsql.h | 5 ++--- server/src/pracrodaotest.cc | 23 +++++++++++++---------- server/src/pracrodaotest.h | 5 ++--- server/src/transactionhandler.cc | 3 +-- 7 files changed, 41 insertions(+), 43 deletions(-) (limited to 'server/src') diff --git a/server/src/database.h b/server/src/database.h index ca0458d..0bc37c0 100644 --- a/server/src/database.h +++ b/server/src/database.h @@ -43,17 +43,16 @@ public: ~Database(); // Make a commit to the db - void commitTransaction(std::string user, - std::string patientid, + void commitTransaction(Transaction &transaction, + Commit &commit, Macro ¯o, - Fields &fields, time_t now = time(NULL)) { if(!dao) return; mutex.lock(); DEBUG(db, "%s, %s, %s,...\n", - user.c_str(), patientid.c_str(), + transaction.user.c_str(), transaction.cpr.c_str(), macro.attributes["name"].c_str()); - dao->commitTransaction(user, patientid, macro, fields, now); + dao->commitTransaction(transaction, commit, macro, now); mutex.unlock(); } diff --git a/server/src/pracrodao.h b/server/src/pracrodao.h index 7825dee..83bd017 100644 --- a/server/src/pracrodao.h +++ b/server/src/pracrodao.h @@ -42,10 +42,9 @@ public: std::string _user, std::string _passwd, std::string _dbname); virtual ~PracroDAO(); - virtual void commitTransaction(std::string user, - std::string patientid, + virtual void commitTransaction(Transaction &transaction, + Commit &commit, Macro ¯o, - Fields &fields, time_t now) = 0; virtual Values getLatestValues(std::string patientid, Macro *macro, diff --git a/server/src/pracrodaopgsql.cc b/server/src/pracrodaopgsql.cc index ee544df..1c96035 100644 --- a/server/src/pracrodaopgsql.cc +++ b/server/src/pracrodaopgsql.cc @@ -85,19 +85,18 @@ PracroDAOPgsql::~PracroDAOPgsql() } } -void PracroDAOPgsql::commitTransaction(std::string user, - std::string patientid, +void PracroDAOPgsql::commitTransaction(Transaction &transaction, + Commit &commit, Macro &_macro, - Fields &fields, time_t now) { DEBUG(db, "(%s, %s, %s, <%u fields>, %ld)\n", - user.c_str(), patientid.c_str(), + transaction.user.c_str(), transaction.cpr.c_str(), _macro.attributes["name"].c_str(), - fields.size(), now); + commit.fields.size(), now); if(!conn) DEBUG(db, "No pgsql connection\n"); - if(fields.size() == 0) return; + if(commit.fields.size() == 0) return; std::string version = _macro.attributes["version"]; std::string macro = _macro.attributes["name"]; @@ -105,27 +104,28 @@ void PracroDAOPgsql::commitTransaction(std::string user, std::string ts; try { - ts = "INSERT INTO transactions (uid, patientid, macro, version," + ts = "INSERT INTO transactions (uid, patientid, template, macro, version," " \"timestamp\", \"user\") VALUES (" " nextval('trseq'), " - " '" + W->esc(patientid) + "', " + " '" + W->esc(transaction.cpr) + "', " + " '" + W->esc(commit.templ) + "', " " '" + W->esc(macro) + "', " " '" + W->esc(version) + "', " " '" + W->esc(timestamp.str()) + "', " - " '" + W->esc(user) + "' " + " '" + W->esc(transaction.user) + "' " ");" ; DEBUG(sql, "Query: %s\n", ts.c_str()); pqxx::result R = W->exec(ts); statements += ts + "\n"; - if(fields.size() > 0) { + if(commit.fields.size() > 0) { // field table lookup ts = "SELECT name FROM fieldnames WHERE name IN ( "; - std::map< std::string, std::string >::iterator i = fields.begin(); + std::map< std::string, std::string >::iterator i = commit.fields.begin(); ts += "'" + W->esc(i->first) + "'"; i++; - while(i != fields.end()) { + while(i != commit.fields.end()) { ts += ", '" + W->esc(i->first) + "'"; i++; } @@ -135,26 +135,26 @@ void PracroDAOPgsql::commitTransaction(std::string user, // statements += ts + "\n"; DEBUG(db, "input fields: %d, output fields: %lu\n", - fields.size(), R.size()); + commit.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(); DEBUG(db, "Storing: %s with value %s\n", - name.c_str(), fields[name].c_str()); + name.c_str(), commit.fields[name].c_str()); ts = "INSERT INTO fields (transaction, name, value) " "VALUES ( currval('trseq'), '" + W->esc(name) + "', '" + - W->esc(fields[name]) + "')"; + W->esc(commit.fields[name]) + "')"; ri++; while(ri != R.end()) { name = (*ri)[0].c_str(); DEBUG(db, "Storing: %s with value %s\n", - name.c_str(), fields[name].c_str()); + name.c_str(), commit.fields[name].c_str()); ts += ", (currval('trseq'), '" + W->esc(name) + "', '" + - W->esc(fields[name]) + "')"; + W->esc(commit.fields[name]) + "')"; ri++; } ts += ";"; diff --git a/server/src/pracrodaopgsql.h b/server/src/pracrodaopgsql.h index b3e0c86..e15a22b 100644 --- a/server/src/pracrodaopgsql.h +++ b/server/src/pracrodaopgsql.h @@ -44,10 +44,9 @@ public: std::string _user, std::string _passwd, std::string _dbname); ~PracroDAOPgsql(); - void commitTransaction(std::string user, - std::string patientid, + void commitTransaction(Transaction &transaction, + Commit &commit, Macro ¯o, - Fields &fields, time_t now); Values getLatestValues(std::string patientid, Macro *macro, diff --git a/server/src/pracrodaotest.cc b/server/src/pracrodaotest.cc index 7e77eb5..45cafc7 100644 --- a/server/src/pracrodaotest.cc +++ b/server/src/pracrodaotest.cc @@ -45,16 +45,18 @@ PracroDAOTest::~PracroDAOTest() DEBUG(db, "Delete test (memory only) database\n"); } -void PracroDAOTest::commitTransaction(std::string user, std::string patientid, - Macro &_macro, Fields &fields, time_t now) +void PracroDAOTest::commitTransaction(Transaction &transaction, + Commit &commit, + Macro &_macro, + time_t now) { DEBUG(db, "(%s, %s, %s, <%u fields>, %ld)\n", - user.c_str(), - patientid.c_str(), + transaction.user.c_str(), + transaction.cpr.c_str(), _macro.attributes["name"].c_str(), - fields.size(), + commit.fields.size(), now); - if(fields.size() == 0) return; + if(commit.fields.size() == 0) return; std::string version = _macro.attributes["version"]; std::string macro = _macro.attributes["name"]; @@ -62,16 +64,17 @@ void PracroDAOTest::commitTransaction(std::string user, std::string patientid, dbrow_t t; t["uid"] = data.trseq.nextval(); - t["patientid"] = patientid; + t["patientid"] = transaction.cpr; + t["template"] = commit.templ; t["macro"] = macro; t["version"] = version; t["timestamp"] = timestamp.str(); - t["user"] = user; + t["user"] = transaction.user; data.transactions.push_back(t); // Iterate fields... - Fields::iterator fi = fields.begin(); - while(fi != fields.end()) { + Fields::iterator fi = commit.fields.begin(); + while(fi != commit.fields.end()) { if(ignore_fieldnames == false) { // Search for it in fieldnames table diff --git a/server/src/pracrodaotest.h b/server/src/pracrodaotest.h index 6ac0e73..34886d0 100644 --- a/server/src/pracrodaotest.h +++ b/server/src/pracrodaotest.h @@ -78,10 +78,9 @@ public: PracroDAOTest(Data &data, bool ignore_fieldnames = false); ~PracroDAOTest(); - void commitTransaction(std::string user, - std::string patientid, + void commitTransaction(Transaction &transaction, + Commit &commit, Macro ¯o, - Fields &fields, time_t now); Values getLatestValues(std::string patientid, Macro *macro, diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index 29220b3..5a4bc6a 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -68,8 +68,7 @@ static std::string handleCommits(Transaction &transaction, Environment &env, std::string resume = resume_parser(*macro, commit); commit.fields["journal.resume"] = resume; - db->commitTransaction(transaction.user, transaction.cpr, *macro, - commit.fields); + db->commitTransaction(transaction, commit, *macro); if(resume != "") { -- cgit v1.2.3