changeset 2588:1f7b459b247b

improved trace logging in SQLite
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 15 May 2018 11:23:25 +0200
parents 010577b52f5f
children 23548462c77d 7fbe3f024ac9
files Core/SQLite/Statement.cpp
diffstat 1 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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 <stdio.h>
 #include <algorithm>
 
-#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;
     }