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.cc76
1 files changed, 74 insertions, 2 deletions
diff --git a/server/src/database.cc b/server/src/database.cc
index 9cdbb7f..2338bb6 100644
--- a/server/src/database.cc
+++ b/server/src/database.cc
@@ -142,6 +142,76 @@ void Database::commit(std::string user,
#endif/*0*/
}
+void Database::putJournal(std::string user,
+ std::string cpr,
+ Macro &_macro,
+ std::string resume,
+ time_t now)
+{
+ std::string version = _macro.attributes["version"];
+ std::string macro = _macro.attributes["name"];
+ std::stringstream timestamp; timestamp << now;
+
+#ifndef WITHOUT_DB
+ pqxx::work W(c);
+#endif/*WITHOUT_DB*/
+
+ std::string ts =
+ "INSERT INTO journal"
+ " VALUES('"+protect(cpr)+"', '"+protect(macro)+"', '"+protect(version)+
+ "', '"+protect(timestamp.str())+"', '"+protect(user)+"', '"+protect(resume)+"')";
+
+ std::stringstream oid;
+
+#ifndef WITHOUT_DB
+ pqxx::result R = W.exec(ts);
+#endif/*WITHOUT_DB*/
+
+#ifdef WITH_DEBUG
+ printf("%s\n", ts.c_str());
+#endif/*WITH_DEBUG*/
+
+#ifndef WITHOUT_DB
+ W.commit();
+#endif/*WITHOUT_DB*/
+}
+
+
+std::string Database::getResume(std::string cpr,
+ std::string macro,
+ time_t oldest)
+{
+ std::string resume;
+
+#ifndef WITHOUT_DB
+ pqxx::work W(c);
+#endif/*WITHOUT_DB*/
+
+ std::stringstream query;
+ query << "SELECT journal";
+ query << " FROM journal";
+ query << " WHERE cpr = '" << protect(cpr) << "'";
+ query << " AND macro = '" << protect(macro) << "'";
+ query << " ORDER BY timestamp;";
+
+#ifdef WITH_DEBUG
+ printf("%s\n", query.str().c_str());
+#endif/*WITH_DEBUG*/
+
+#ifndef WITHOUT_DB
+ pqxx::result R = W.exec(query.str());
+
+ pqxx::result::const_iterator ri = R.begin();
+ while(ri != R.end()) {
+ pqxx::result::tuple t = *ri;
+ resume = t[0].c_str();
+ ri++;
+ }
+#endif/*WITHOUT_DB*/
+
+ return resume;
+}
+
Values Database::getValues(std::string cpr,
Fieldnames &fields,
@@ -275,10 +345,10 @@ ALTER TABLE fields OWNER TO pracro;
int main()
{
- Database db;
+ Database db("localhost", "pracro", "pracro");
time_t now = time(NULL);
-
+ /*
Macro macro;
macro.attributes["name"] = "testmacro";
macro.attributes["version"] = "1.0";
@@ -300,6 +370,8 @@ int main()
printf("%s -> %s (%u)\n", i->first.c_str(), v.value.c_str(), (unsigned int)v.timestamp);
i++;
}
+ */
+ printf(db.getResume("1505050505", "B.2.5", now - 60 * 60 * 24).c_str());
}
#endif/*TEST_DATABASE*/