[evolution-data-server] sqlitedb: Give better control on debug output



commit e980b493e6ae0b7feed176372fa4d5329332c62c
Author: Mathias Hasselmann <mathias openismus com>
Date:   Fri Feb 1 13:19:54 2013 +0100

    sqlitedb: Give better control on debug output
    
    The value passed to BOOKSQL_DEBUG is now interpreted as number.
    SQLite's explain facilities only are used when its value is
    bigger than one.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692998

 .../libedata-book/e-book-backend-sqlitedb.c        |   23 +++++++++++++------
 1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 87e5d64..14ad7e2 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -324,18 +324,26 @@ print_debug_cb (gpointer ref,
 static void
 book_backend_sql_debug (sqlite3 *db,
                         const gchar *stmt,
+                        gint debug_level,
                         gint (*callback)(gpointer ,gint,gchar **,gchar **),
                         gpointer data,
                         GError **error)
 {
-	gchar *debug;
 	GError *local_error = NULL;
-	debug = g_strconcat ("EXPLAIN QUERY PLAN ", stmt, NULL);
 
 	g_printerr ("DEBUG STATEMENT: %s\n", stmt);
-	book_backend_sql_exec_real (db, debug, print_debug_cb, NULL, &local_error);
-	g_printerr ("DEBUG STATEMENT END: %s%s\n", local_error ? "Error: " : "", local_error ? local_error->message : "Success");
-	g_free (debug);
+
+	if (debug_level > 1) {
+		gchar *debug = g_strconcat ("EXPLAIN QUERY PLAN ", stmt, NULL);
+		book_backend_sql_exec_real (db, debug, print_debug_cb, NULL, &local_error);
+		g_free (debug);
+	}
+
+	if (local_error) {
+		g_printerr ("DEBUG STATEMENT END: Error: %s\n", local_error->message);
+	} else if (debug_level > 1) {
+		g_printerr ("DEBUG STATEMENT END: Success\n");
+	}
 
 	g_clear_error (&local_error);
 }
@@ -350,11 +358,12 @@ book_backend_sql_exec (sqlite3 *db,
 	static gint booksql_debug = -1;
 
 	if (booksql_debug == -1) {
-		booksql_debug = g_getenv ("BOOKSQL_DEBUG") != NULL ? 1 : 0;
+		const gchar *const tmp = g_getenv ("BOOKSQL_DEBUG");
+		booksql_debug = (tmp != NULL ? MAX (0, atoi (tmp)) : 0);
 	}
 
 	if (booksql_debug)
-		book_backend_sql_debug (db, stmt, callback, data, error);
+		book_backend_sql_debug (db, stmt, booksql_debug, callback, data, error);
 
 	return book_backend_sql_exec_real (db, stmt, callback, data, error);
 }



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