db: sql logs can be enabled with --enable-sql-log command line option
authorImran Zaman <imran.zaman@linux.intel.com>
Wed, 29 May 2013 09:12:44 +0000 (12:12 +0300)
committerImran Zaman <imran.zaman@linux.intel.com>
Wed, 29 May 2013 10:17:39 +0000 (13:17 +0300)
configure.ac
src/common/db/gsignond-db-sql-database.c

index c0b7190..0198d14 100644 (file)
@@ -84,6 +84,14 @@ echo -n "enable debug features... "
 echo $enable_debug
 if test "x$enable_debug" = "xyes" ; then
     AC_DEFINE(ENABLE_DEBUG, [1], [Enable debug features])
+    AC_ARG_ENABLE(sqllog,
+          [  --enable-sql-log          enable sql log feature],
+          [enable_sql_log=yes], [enable_sql_log=no])
+    echo -n "enable sql log feature... "
+    echo $enable_sql_log
+    if test "x$enable_sql_log" = "xyes" ; then
+        AC_DEFINE(ENABLE_SQL_LOG, [1], [Enable SQL log feature])
+    fi
 fi
 
 AM_CONDITIONAL(USE_GTESTDBUS, [test x$gtestdbus = xyes])
index d7c6a2d..79f7513 100644 (file)
@@ -66,6 +66,15 @@ _gsignond_db_sql_database_is_open (GSignondDbSqlDatabase *self)
     return self->priv->db != NULL;
 }
 
+#ifdef ENABLE_SQL_LOG
+void trace_callback (void *s, const char *stmt)
+{
+    if (stmt) {
+        DBG ("SQLITE TRACE: %s", stmt);
+    }
+}
+#endif
+
 gboolean
 _gsignond_db_sql_database_open (
         GSignondDbSqlDatabase *self,
@@ -96,6 +105,10 @@ _gsignond_db_sql_database_open (
             WARN ("setting file permissions on %s failed", filename);
     }
 
+#ifdef ENABLE_SQL_LOG
+    sqlite3_trace (self->priv->db, trace_callback, NULL);
+#endif
+
     if (!GSIGNOND_DB_SQL_DATABASE_GET_CLASS (self)->create (self)) {
         GSIGNOND_DB_SQL_DATABASE_GET_CLASS (self)->close (self);
         return FALSE;