summaryrefslogtreecommitdiff
path: root/server/src/database.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/database.cc')
-rw-r--r--server/src/database.cc62
1 files changed, 29 insertions, 33 deletions
diff --git a/server/src/database.cc b/server/src/database.cc
index 1a48925..ad6bbe0 100644
--- a/server/src/database.cc
+++ b/server/src/database.cc
@@ -26,9 +26,8 @@
*/
#include "database.h"
-#include "tostring.h"
+//#include "tostring.h"
#include "uid.h"
-#include <time.h>
Database::Database(std::string hostname, std::string user, std::string password)
: c("host=" + hostname +
@@ -42,47 +41,44 @@ Database::~Database()
{
}
-int Database::post(Transaction &transaction)
+int Database::post(std::string &user, std::string &cpr, std::string &time, Commit &commit)
{
UID uid;
- std::string now = toString((unsigned int)time(NULL));
try {
pqxx::work W(c);
- Commits::iterator i = transaction.commits.begin();
- while(i != transaction.commits.end()) {
- Commit &commit = *i;
- // std::string transid = transidbase + toString(idx);
-
- // Insert transaction entry
- std::string sql = "INSERT INTO transactions VALUES('" +
- transaction.cpr + "', '" +
+ // std::string transid = transidbase + toString(idx);
+
+ // Insert transaction entry
+ std::string sql = "INSERT INTO transactions VALUES('" +
+ cpr + "', '" +
+ uid.toString() + "', '" +
+ commit.macro + "', '" +
+ commit.version + "', '" +
+ time + "', '" +
+ user + "')";
+ W.exec(sql);
+
+ // Insert field entries
+ Fields::iterator j = commit.fields.begin();
+ while(j != commit.fields.end()) {
+ // std::string name = j->first;
+ // std::string value = j->second;
+
+ sql = "INSERT INTO fields VALUES('" +
uid.toString() + "', '" +
- commit.macro + "', '" +
- commit.version + "', '" +
- now + "', '" +
- transaction.user + "')";
+ j->first + "', '" +
+ j->second + "')";
+ // name + "', '" +
+ // value + "')";
W.exec(sql);
-
- // Insert field entries
- Fields::iterator j = commit.fields.begin();
- while(j != commit.fields.end()) {
- Field &field = *j;
-
- sql = "INSERT INTO fields VALUES('" +
- uid.toString() + "', '" +
- field.name + "', '" +
- field.value + "')";
- W.exec(sql);
-
- j++;
- }
-
- uid++;
- i++;
+
+ j++;
}
+ uid++;
+
W.commit();
} catch(const std::exception &e) {
// throw PostgreSQLException(e.what());