# HG changeset patch # User Sebastien Jodogne # Date 1526376205 -7200 # Node ID 1f7b459b247bea25cd3feab228e3fc0077eaf770 # Parent 010577b52f5fe02146cc5f7eac228c945706b73c improved trace logging in SQLite diff -r 010577b52f5f -r 1f7b459b247b Core/SQLite/Statement.cpp --- a/Core/SQLite/Statement.cpp Fri May 11 09:32:15 2018 +0200 +++ b/Core/SQLite/Statement.cpp Tue May 15 11:23:25 2018 +0200 @@ -46,8 +46,21 @@ #include #include -#if ORTHANC_SQLITE_STANDALONE != 1 -#include "../Logging.h" +#if (ORTHANC_SQLITE_STANDALONE == 1) +// Trace logging is disabled if this SQLite wrapper is used +// independently of Orthanc +# define LOG_CREATE(message); +# define LOG_APPLY(message); +#elif defined(NDEBUG) +// Trace logging is disabled in release builds +# include "../Logging.h" +# define LOG_CREATE(message); +# define LOG_APPLY(message); +#else +// Trace logging is enabled in debug builds +# include "../Logging.h" +# define LOG_CREATE(message) VLOG(1) << "SQLite::Statement create: " << message; +# define LOG_APPLY(message); // VLOG(1) << "SQLite::Statement apply: " << message; #endif #include "sqlite3.h" @@ -56,6 +69,7 @@ #define snprintf _snprintf #endif + namespace Orthanc { namespace SQLite @@ -103,6 +117,7 @@ reference_(database.GetCachedStatement(id, sql.c_str())) { Reset(true); + LOG_CREATE(sql); } @@ -112,6 +127,7 @@ reference_(database.GetCachedStatement(id, sql)) { Reset(true); + LOG_CREATE(sql); } @@ -119,6 +135,7 @@ const std::string& sql) : reference_(database.GetWrappedObject(), sql.c_str()) { + LOG_CREATE(sql); } @@ -126,23 +143,20 @@ const char* sql) : reference_(database.GetWrappedObject(), sql) { + LOG_CREATE(sql); } bool Statement::Run() { -#if ORTHANC_SQLITE_STANDALONE != 1 - VLOG(1) << "SQLite::Statement::Run " << sqlite3_sql(GetStatement()); -#endif + LOG_APPLY(sqlite3_sql(GetStatement())); return CheckError(sqlite3_step(GetStatement()), ErrorCode_SQLiteCannotRun) == SQLITE_DONE; } bool Statement::Step() { -#if ORTHANC_SQLITE_STANDALONE != 1 - VLOG(1) << "SQLite::Statement::Step " << sqlite3_sql(GetStatement()); -#endif + LOG_APPLY(sqlite3_sql(GetStatement())); return CheckError(sqlite3_step(GetStatement()), ErrorCode_SQLiteCannotStep) == SQLITE_ROW; }