summaryrefslogtreecommitdiff
path: root/server/src/database.cc
diff options
context:
space:
mode:
authordeva <deva>2008-09-22 12:17:51 +0000
committerdeva <deva>2008-09-22 12:17:51 +0000
commit1b9cf53926a6627b9f8ed00a8dc1f4a784e6f295 (patch)
tree1a82a8e8ff50cc9d71e04867ca942e187605a1d9 /server/src/database.cc
parent8352be99474fbbeed5795e8610b3d9a23e38b1cd (diff)
Added resume storing to the db, and made the outputted xml use it. Added captions to the macro tags from the window-tag caption attribute. Made all template attributes fall through to the client.
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*/