From 551d4aa1be9f4d256df3fadca9a005a0f316adf8 Mon Sep 17 00:00:00 2001 From: bertho Date: Thu, 5 Feb 2009 01:26:26 +0000 Subject: Add a flexible debug interface. Please read the documentation. --- server/src/database.cc | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'server/src/database.cc') diff --git a/server/src/database.cc b/server/src/database.cc index ec1e736..9406e1e 100644 --- a/server/src/database.cc +++ b/server/src/database.cc @@ -29,6 +29,7 @@ #include #include +#include "debug.h" Database::Database(std::string hostname, std::string user, std::string password) #ifndef WITHOUT_DB @@ -81,18 +82,15 @@ void Database::commit(std::string user, } ts += ")"; R = W.exec(ts); -#ifdef WITH_DEBUG - printf("Database::commit: input fields: %d, output fields: %lu\n", fields.size(), R.size()); -#endif/*WITHOUT_DB*/ + PRACRO_DEBUG(db, "Database::commit: input fields: %d, output fields: %lu\n", fields.size(), R.size()); pqxx::result::const_iterator ri = R.begin(); // Store known fields while(ri != R.end()) { pqxx::result::tuple t = *ri; std::string name = t[0].c_str(); -#ifdef WITH_DEBUG - printf("Storing: %s with value %s\n", name.c_str(), fields[name].c_str()); -#endif/*WITHOUT_DB*/ + + PRACRO_DEBUG(db, "Storing: %s with value %s\n", name.c_str(), fields[name].c_str()); ts = "INSERT INTO fields VALUES (" " '" + W.esc(oid.str()) + "', " @@ -106,16 +104,15 @@ void Database::commit(std::string user, } W.commit(); } catch(std::exception &e) { - printf("Query failed: %s: %s\n", e.what(), ts.c_str()); + PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str()); } #else #ifdef WITH_DEBUG std::map< std::string, std::string >::iterator i = fields.begin(); while(i != fields.end()) { - printf("Storing field '%s': '%s'\n", i->first, i->second); + PRACRO_DEBUG(db, "Storing field '%s': '%s'\n", i->first, i->second); i++; } - #endif/*WITH_DEBUG*/ #endif/*WITHOUT_DB*/ } @@ -146,11 +143,11 @@ void Database::putResume(std::string user, pqxx::result R = W.exec(ts); W.commit(); } catch(std::exception &e) { - printf("Query failed: %s: %s\n", e.what(), ts.c_str()); + PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str()); } #else #ifdef WITH_DEBUG - printf("INSERT INTO journal VALUES ('%s', '%s', '%s', '%s', '%s', '%s')\n", + PRACRO_DEBUG(db, "INSERT INTO journal VALUES ('%s', '%s', '%s', '%s', '%s', '%s')\n", cpr.c_str(), macro.c_str(), version.c_str(), @@ -188,11 +185,11 @@ std::string Database::getResume(std::string cpr, ri++; } } catch (std::exception &e) { - printf("Query failed: %s: %s\n", e.what(), query.c_str()); + PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str()); } #else #ifdef WITH_DEBUG - printf("SELECT journal FROM journal WHERE cpr = '%s' AND macro = '%s' ORDER BY timestamp", cpr.c_str(), macro.c_str()); + PRACRO_DEBUG(db, "SELECT journal FROM journal WHERE cpr = '%s' AND macro = '%s' ORDER BY timestamp", cpr.c_str(), macro.c_str()); #endif/*WITH_DEBUG*/ #endif/*WITHOUT_DB*/ @@ -240,11 +237,11 @@ Values Database::getValues(std::string cpr, ri++; } } catch (std::exception &e) { - printf("Query failed: %s: %s\n", e.what(), query.c_str()); + PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str()); } #else #ifdef WITH_DEBUG - printf("getValues(%s, , %ld) -- not implemented without database...\n", cpr.c_str(), oldest); + PRACRO_DEBUG(db, "getValues(%s, , %ld) -- not implemented without database...\n", cpr.c_str(), oldest); #endif/*WITH_DEBUG*/ #endif/*WITHOUT_DB*/ @@ -269,11 +266,11 @@ bool Database::checkMacro(std::string cpr, pqxx::result R = W.exec(query); return R.size() != 0; } catch(std::exception &e) { - printf("Query failed: %s: %s\n", e.what(), query.c_str()); + PRACRO_ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str()); } #else #ifdef WITH_DEBUG - printf("SELECT oid FROM transactions WHERE cpr = '%s' AND macro = '%s' AND timestamp >= %ld ORDER BY timestamp\n", + PRACRO_DEBUG(db, "SELECT oid FROM transactions WHERE cpr = '%s' AND macro = '%s' AND timestamp >= %ld ORDER BY timestamp\n", cpr.c_str(), macro.c_str(), oldest); #endif/*WITH_DEBUG*/ #endif/*WITHOUT_DB*/ -- cgit v1.2.3