From 1b9cf53926a6627b9f8ed00a8dc1f4a784e6f295 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 22 Sep 2008 12:17:51 +0000 Subject: 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. --- server/src/database.cc | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 2 deletions(-) (limited to 'server/src/database.cc') 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*/ -- cgit v1.2.3