Permalink
Browse files

Add the environment variable ZIF_SQL_DEBUG for debugging queries

  • Loading branch information...
1 parent 08cc0b7 commit 5130d86fba1c69e4e37f628d17ab604b81cbea93 @hughsie committed Sep 14, 2011
Showing with 34 additions and 1 deletion.
  1. +15 −0 libzif/zif-md-filelists-sql.c
  2. +15 −0 libzif/zif-md-primary-sql.c
  3. +4 −1 man/zif.sgml
@@ -241,6 +241,11 @@ zif_md_filelists_sql_get_files (ZifMd *md, ZifPackage *package,
statement = g_strdup_printf ("SELECT dirname, filenames FROM packages p, filelist f WHERE "
"p.pkgKey = f.pkgKey AND "
"p.pkgId = '%s'", pkgid);
+ if (g_getenv ("ZIF_SQL_DEBUG") != NULL) {
+ g_debug ("On %s\n%s",
+ zif_md_get_filename_uncompressed (md),
+ statement);
+ }
rc = sqlite3_exec (md_filelists_sql->priv->db, statement, zif_md_filelists_sql_sqlite_get_files_cb, &files, &error_msg);
g_free (statement);
if (rc != SQLITE_OK) {
@@ -337,6 +342,11 @@ zif_md_filelists_sql_search_file (ZifMd *md, gchar **search,
/* populate _array with guint pkgKey */
statement = g_strdup_printf ("SELECT filenames, pkgKey FROM filelist WHERE dirname = '%s'", dirname);
+ if (g_getenv ("ZIF_SQL_DEBUG") != NULL) {
+ g_debug ("On %s\n%s",
+ zif_md_get_filename_uncompressed (md),
+ statement);
+ }
rc = sqlite3_exec (md_filelists_sql->priv->db, statement, zif_md_filelists_sql_sqlite_get_pkgkey_cb, data, &error_msg);
g_free (statement);
g_free (dirname);
@@ -370,6 +380,11 @@ zif_md_filelists_sql_search_file (ZifMd *md, gchar **search,
/* convert the pkgKey to a pkgId */
key = GPOINTER_TO_UINT (g_ptr_array_index (pkgkey_array, i));
statement = g_strdup_printf ("SELECT pkgId FROM packages WHERE pkgKey = %i LIMIT 1", key);
+ if (g_getenv ("ZIF_SQL_DEBUG") != NULL) {
+ g_debug ("On %s\n%s",
+ zif_md_get_filename_uncompressed (md),
+ statement);
+ }
rc = sqlite3_exec (md_filelists_sql->priv->db, statement, zif_md_filelists_sql_sqlite_get_id_cb, &pkgid, &error_msg);
g_free (statement);
if (rc != SQLITE_OK) {
@@ -214,6 +214,11 @@ zif_md_primary_sql_search (ZifMdPrimarySql *md, const gchar *statement,
goto out;
data->packages = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+ if (g_getenv ("ZIF_SQL_DEBUG") != NULL) {
+ g_debug ("On %s\n%s",
+ zif_md_get_filename_uncompressed (ZIF_MD (md)),
+ statement);
+ }
rc = sqlite3_exec (md->priv->db, statement,
zif_md_primary_sql_sqlite_create_package_cb,
data, &error_msg);
@@ -621,6 +626,11 @@ zif_md_primary_sql_what_depends (ZifMd *md, const gchar *table_name, GPtrArray *
g_string_append (statement, "END;\n");
/* execute the query */
+ if (g_getenv ("ZIF_SQL_DEBUG") != NULL) {
+ g_debug ("On %s\n%s",
+ zif_md_get_filename_uncompressed (md),
+ statement->str);
+ }
rc = sqlite3_exec (md_primary_sql->priv->db,
statement->str,
zif_md_primary_sql_sqlite_create_package_cb,
@@ -765,6 +775,11 @@ zif_md_primary_sql_get_depends (ZifMd *md,
version,
release,
zif_package_get_arch (package));
+ if (g_getenv ("ZIF_SQL_DEBUG") != NULL) {
+ g_debug ("On %s\n%s",
+ zif_md_get_filename_uncompressed (md),
+ statement);
+ }
rc = sqlite3_exec (md_primary_sql->priv->db,
statement,
zif_md_primary_sql_sqlite_depend_cb,
View
@@ -51,7 +51,10 @@
<refsect1>
<title>ENVIRONMENT VARIABLES</title>
<para>Setting <command>ZIF_DEPSOLVE_DEBUG</command> is useful for
- debugging dependency depsolve failurs.
+ debugging dependency depsolve failures.
+ </para>
+ <para>Setting <command>ZIF_SQL_DEBUG</command> is useful for
+ debugging SQL query failures.
</para>
</refsect1>
<refsect1>

0 comments on commit 5130d86

Please sign in to comment.