diff options
Diffstat (limited to 'server/src/database.cc')
-rw-r--r-- | server/src/database.cc | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/server/src/database.cc b/server/src/database.cc index 35d9214..2b8b83c 100644 --- a/server/src/database.cc +++ b/server/src/database.cc @@ -27,7 +27,9 @@ #include "database.h" Database::Database(std::string hostname, std::string user, std::string password) +#ifndef WITHOUT_DB : c("host=" + hostname + " user=" + user + " password=" + password + " dbname=pracro") +#endif/*WITHOUT_DB*/ { } @@ -57,15 +59,23 @@ void Database::commit(std::string user, 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 transactions" " VALUES('"+cpr+"', '"+macro+"', '"+version+"', '"+timestamp.str()+"', '"+user+"')"; - pqxx::result R = W.exec(ts); + std::stringstream oid; - std::stringstream oid; oid << R.inserted_oid(); +#ifndef WITHOUT_DB + pqxx::result R = W.exec(ts); + oid << R.inserted_oid(); +#else + oid << "###GENERATED_OID###"; + printf("%s\n", ts.c_str()); +#endif/*WITHOUT_DB*/ std::map< std::string, std::string >::iterator i = fields.begin(); while(i != fields.end()) { @@ -74,12 +84,18 @@ void Database::commit(std::string user, "INSERT INTO fields" " VALUES('"+oid.str()+"', '"+i->first+"', '"+i->second+"')"; +#ifndef WITHOUT_DB W.exec(fs); +#else + printf("%s\n", fs.c_str()); +#endif/*WITHOUT_DB*/ i++; } +#ifndef WITHOUT_DB W.commit(); +#endif/*WITHOUT_DB*/ #if 0 try { @@ -100,7 +116,9 @@ Values Database::getValues(std::string cpr, time_t oldest) { Values values; +#ifndef WITHOUT_DB pqxx::work W(c); +#endif/*WITHOUT_DB*/ std::stringstream query; query << "SELECT fields.name, fields.value, transactions.timestamp"; @@ -121,6 +139,7 @@ Values Database::getValues(std::string cpr, query << " ORDER BY transactions.timestamp"; +#ifndef WITHOUT_DB pqxx::result R = W.exec(query.str()); pqxx::result::const_iterator ri = R.begin(); @@ -139,6 +158,9 @@ Values Database::getValues(std::string cpr, ri++; } +#else + printf("%s\n", query.str().c_str()); +#endif/*WITHOUT_DB*/ return values; } @@ -147,7 +169,9 @@ bool Database::checkMacro(std::string cpr, std::string macro, time_t oldest) { +#ifndef WITHOUT_DB pqxx::work W(c); +#endif/*WITHOUT_DB*/ std::stringstream query; query << "SELECT oid"; @@ -157,6 +181,7 @@ bool Database::checkMacro(std::string cpr, query << " AND timestamp >= " << oldest; query << " ORDER BY timestamp"; +#ifndef WITHOUT_DB try { pqxx::result R = W.exec(query.str()); @@ -164,6 +189,9 @@ bool Database::checkMacro(std::string cpr, } catch( ... ) { return false; } +#else + return false; +#endif/*WITHOUT_DB*/ } /* |