diff options
author | bertho <bertho> | 2009-02-05 01:26:26 +0000 |
---|---|---|
committer | bertho <bertho> | 2009-02-05 01:26:26 +0000 |
commit | 551d4aa1be9f4d256df3fadca9a005a0f316adf8 (patch) | |
tree | b3cae7ee51d5dc64d0d07ae7deffdd67d4f3f371 /server/src/database.cc | |
parent | 3ad20fdd0c8d5c20f0c02e3d1ad2e1e6b0f2a078 (diff) |
Add a flexible debug interface. Please read the documentation.
Diffstat (limited to 'server/src/database.cc')
-rw-r--r-- | server/src/database.cc | 31 |
1 files changed, 14 insertions, 17 deletions
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 <config.h> #include <stdlib.h> +#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, <fields...>, %ld) -- not implemented without database...\n", cpr.c_str(), oldest); + PRACRO_DEBUG(db, "getValues(%s, <fields...>, %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*/ |