From a5d78e33085399d04fabeacf8142dbfe55992e7a Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 9 Jun 2008 14:51:41 +0000 Subject: Added check to see if macro already has been committed. For later use with dependency checking. --- server/src/database.cc | 25 ++++++++++++++++++++++++- server/src/database.h | 5 +++++ server/src/server.cc | 9 ++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/src/database.cc b/server/src/database.cc index 62454a2..35d9214 100644 --- a/server/src/database.cc +++ b/server/src/database.cc @@ -143,6 +143,29 @@ Values Database::getValues(std::string cpr, return values; } +bool Database::checkMacro(std::string cpr, + std::string macro, + time_t oldest) +{ + pqxx::work W(c); + + std::stringstream query; + query << "SELECT oid"; + query << " FROM transactions"; + query << " WHERE cpr = '" << cpr << "'"; + query << " AND macro = '" << macro << "'"; + query << " AND timestamp >= " << oldest; + query << " ORDER BY timestamp"; + + try { + pqxx::result R = W.exec(query.str()); + + return R.size() != 0; + } catch( ... ) { + return false; + } +} + /* -- As root: -- #createuser -P -h localhost -U postgres @@ -160,7 +183,7 @@ DROP TABLE transactions; CREATE TABLE transactions ( "cpr" varchar(11), - "makro" text, + "macro" text, "version" text, "timestamp" bigint, "user" text diff --git a/server/src/database.h b/server/src/database.h index 31d69fc..85f8cd7 100644 --- a/server/src/database.h +++ b/server/src/database.h @@ -65,6 +65,11 @@ public: Fieldnames &fieldnames, time_t oldest = 0); + // Check if a macro has been committed. + bool checkMacro(std::string cpr, + std::string macro, + time_t oldest = 0); + // Connect to the db void connect() {} diff --git a/server/src/server.cc b/server/src/server.cc index a94a0f8..c0ec223 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -168,7 +168,10 @@ static void connection(TCPSocket &socket) while(mi2 != templ->course.macroes.end()) { Macro ¯o = (*mi2); - answer += " \n"; + answer += " \n"); @@ -280,7 +283,7 @@ void server() char request[] = "\n" "\n" - " \n" + " \n" "\n"; int main() -- cgit v1.2.3