summaryrefslogtreecommitdiff
path: root/server/src/database.cc
diff options
context:
space:
mode:
authordeva <deva>2007-09-17 13:16:26 +0000
committerdeva <deva>2007-09-17 13:16:26 +0000
commit11afe913ff34c8b466a1635ca15d99a684904b78 (patch)
tree5ee1312168e7a4a1ff0b7df60dfa5292edc562f5 /server/src/database.cc
parentb70c9b6843e15ee5764b8457acea930af0d2b285 (diff)
Added UID class for use when generating transaction ids.
Diffstat (limited to 'server/src/database.cc')
-rw-r--r--server/src/database.cc52
1 files changed, 29 insertions, 23 deletions
diff --git a/server/src/database.cc b/server/src/database.cc
index 4bf9c61..1d4915e 100644
--- a/server/src/database.cc
+++ b/server/src/database.cc
@@ -27,9 +27,8 @@
#include "database.h"
#include "tostring.h"
+#include "uid.h"
#include <time.h>
-#include <sys/types.h>
-#include <unistd.h>
Database::Database(std::string hostname, std::string user, std::string password)
: c("host=" + hostname +
@@ -37,18 +36,6 @@ Database::Database(std::string hostname, std::string user, std::string password)
" password=" + password +
" dbname=pracro")
{
- /*
- try {
- char port_string[32];
- sprintf(port_string, "%d", port);
- std::string hoststring = "host=" + host + " port=" + port_string +
- " user=" + user + " password=" + password + " dbname=" + database;
- c = new pqxx::connection(hoststring);
-
- } catch(const std::exception &e) {
- //throw PostgreSQLException(e.what());
- }
- */
}
Database::~Database()
@@ -57,26 +44,24 @@ Database::~Database()
int Database::post(Transaction &transaction)
{
- time_t now = time(NULL);
- std::string transidbase = toString((unsigned int)now) + "-"
- + toString((unsigned int)getpid()) + "-"; // Here we put the commit index
+ UID uid;
+ std::string now = toString((unsigned int)time(NULL));
try {
pqxx::work W(c);
Commits::iterator i = transaction.commits.begin();
- unsigned int idx = 0;
while(i != transaction.commits.end()) {
Commit &commit = *i;
- std::string transid = transidbase + toString(idx);
+ // std::string transid = transidbase + toString(idx);
// Insert transaction entry
std::string sql = "INSERT INTO transactions VALUES('" +
transaction.cpr + "', '" +
- transid + "', '" +
+ uid.toString() + "', '" +
commit.macro + "', '" +
commit.version + "', '" +
- toString((unsigned int)now) + "', '" +
+ now + "', '" +
commit.user + "')";
W.exec(sql);
@@ -86,7 +71,7 @@ int Database::post(Transaction &transaction)
Field &field = *j;
sql = "INSERT INTO fields VALUES('" +
- transid + "', '" +
+ uid.toString() + "', '" +
field.name + "', '" +
field.value + "')";
W.exec(sql);
@@ -94,7 +79,7 @@ int Database::post(Transaction &transaction)
j++;
}
- idx++;
+ uid++;
i++;
}
@@ -105,6 +90,27 @@ int Database::post(Transaction &transaction)
return 0;
}
+/*
+int Database::getTransaction(cpr, transid)
+{
+ SELECT fields.name, fields.value
+ FROM transactions, fields
+ WHERE transactions.cpr='2003791613'
+ AND transactions.transaction='1234567890'
+ AND transactions.transaction=fields.transaction
+}
+*/
+
+/*
+int Database::getMakro(cpr, macro)
+{
+ SELECT fields.name, fields.value
+ FROM transactions, fields
+ WHERE transactions.cpr='2003791613'
+ AND transactions.macro='dims'
+ AND transactions.transaction=fields.transaction
+}
+*/
// som root
// # createuser -P -h localhost -U postgres