[tracker/wip/carlosg/sql-statements-debug] libtracker-data: Provide better sql-statements debug output




commit aa40f98ae3f67d368de22345a2da32aacf267619
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Aug 29 15:54:06 2020 +0200

    libtracker-data: Provide better sql-statements debug output
    
    Where sql-statements is, it basically debugs statements being compiled,
    given those may be cached and reused, that doesn't tell the full picture
    about the SQL statements actually happening.
    
    Change this debug output so that's actually what happens, this will be a
    lot more verbose, and will try to print a fully expanded SQL string, so
    all bound parameters are expanded to their string value.

 src/libtracker-data/tracker-db-interface-sqlite.c | 33 ++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c 
b/src/libtracker-data/tracker-db-interface-sqlite.c
index 46b2aab46..d758f92e0 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -2613,7 +2613,6 @@ tracker_db_interface_prepare_stmt (TrackerDBInterface  *db_interface,
        sqlite3_stmt *sqlite_stmt;
        int retval;
 
-       TRACKER_NOTE (SQL_STATEMENTS, g_message ("Preparing query: '%s'", full_query));
        retval = sqlite3_prepare_v2 (db_interface->db, full_query, -1, &sqlite_stmt, NULL);
 
        if (retval != SQLITE_OK) {
@@ -2851,6 +2850,22 @@ execute_stmt (TrackerDBInterface  *interface,
 
        g_atomic_int_inc (&interface->n_active_cursors);
 
+#ifdef G_ENABLE_DEBUG
+        if (TRACKER_DEBUG_CHECK (SQL_STATEMENTS)) {
+               gchar *full_query;
+
+               full_query = sqlite3_expanded_sql (stmt);
+
+               if (full_query) {
+                       g_message ("Executing update: '%s'", full_query);
+                       sqlite3_free (full_query);
+               } else {
+                       g_message ("Executing update: '%s'",
+                                  sqlite3_sql (stmt));
+               }
+        }
+#endif
+
        while (result == SQLITE_OK  ||
               result == SQLITE_ROW) {
 
@@ -3183,6 +3198,22 @@ tracker_db_cursor_sqlite_new (TrackerDBStatement  *ref_stmt,
        iface = ref_stmt->db_interface;
        g_atomic_int_inc (&iface->n_active_cursors);
 
+#ifdef G_ENABLE_DEBUG
+        if (TRACKER_DEBUG_CHECK (SQL_STATEMENTS)) {
+               gchar *full_query;
+
+               full_query = sqlite3_expanded_sql (ref_stmt->stmt);
+
+               if (full_query) {
+                       g_message ("Executing query: '%s'", full_query);
+                       sqlite3_free (full_query);
+               } else {
+                       g_message ("Executing query: '%s'",
+                                  sqlite3_sql (ref_stmt->stmt));
+               }
+        }
+#endif
+
        cursor = g_object_new (TRACKER_TYPE_DB_CURSOR, NULL);
 
        cursor->finished = FALSE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]