From 4a90fa8c2c9244e52c1ac08cbfcb62b0e4851010 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 13 Oct 2008 14:24:50 +0000 Subject: Created a fieldname table, and only stores a field/value pairs, if the field exists in this fieldname table. --- server/src/database.cc | 71 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 14 deletions(-) (limited to 'server/src') diff --git a/server/src/database.cc b/server/src/database.cc index 371a870..08e8465 100644 --- a/server/src/database.cc +++ b/server/src/database.cc @@ -69,17 +69,7 @@ void Database::commit(std::string user, Fields &fields, time_t now) { - // / Create transaction ID (transaction OID?) - // { - // \ Commit transaction data - - // Commit all field values using transaction ID. - - // INSERT INTO transactions VALUES('cpr', 'macro', 'version', 'timestamp', 'user') - // Returns INSERT oid count - // count == 1, oid is oid of newly inserted transaction. - - // INSERT INTO fields VALUES('oid', 'field', 'value') + if(fields.size() == 0) return; std::string version = _macro.attributes["version"]; std::string macro = _macro.attributes["name"]; @@ -107,12 +97,35 @@ void Database::commit(std::string user, printf("%s\n", ts.c_str()); #endif/*WITH_DEBUG*/ + // + // FIELD TABLE LOOKUP + // + std::stringstream query; + query << "SELECT name"; + query << " FROM fieldnames"; std::map< std::string, std::string >::iterator i = fields.begin(); while(i != fields.end()) { + if(i == fields.begin()) query << " WHERE name = '" << protect(i->first) << "'"; + else query << " OR name = '" << protect(i->first) << "';"; + i++; + } +#ifdef WITH_DEBUG + printf("%s\n", query.str().c_str()); +#endif/*WITH_DEBUG*/ + +#ifndef WITHOUT_DB + R = W.exec(query.str()); + + pqxx::result::const_iterator ri = R.begin(); + while(ri != R.end()) { + pqxx::result::tuple t = *ri; + std::string name = t[0].c_str(); + + printf("Storing: %s with value %s\n", name.c_str(), fields[name].c_str()); std::string fs = "INSERT INTO fields" - " VALUES('"+protect(oid.str())+"', '"+protect(i->first)+"', '"+protect(i->second)+"')"; + " VALUES('"+protect(oid.str())+"', '"+protect(name)+"', '"+protect(fields[name])+"')"; #ifndef WITHOUT_DB W.exec(fs); @@ -121,9 +134,14 @@ void Database::commit(std::string user, #ifdef WITH_DEBUG printf("%s\n", fs.c_str()); #endif/*WITH_DEBUG*/ - - i++; + + + ri++; } +#endif/*WITHOUT_DB*/ + // + // end of FIELD TABLE LOOKUP + // #ifndef WITHOUT_DB W.commit(); @@ -339,6 +357,31 @@ CREATE TABLE fields WITH OIDS; ALTER TABLE fields OWNER TO pracro; +DROP TABLE journal; + +CREATE TABLE journal +( + cpr character varying(11), + macro text, + "version" text, + "timestamp" bigint, + "user" text, + journal text +) +WITH OIDS; +ALTER TABLE journal OWNER TO pracro; + +DROP TABLE fieldnames; + +CREATE TABLE fieldnames +( + name text, + description text, + "timestamp" bigint +) +WITH OIDS; +ALTER TABLE fieldnames OWNER TO pracro; + -- primary key(oid) ?? */ -- cgit v1.2.3