[evolution-data-server/gnome-3-8] EBookBackendSqliteDB: Avoid summary introspection on initial creation.



commit 2f0945c6494b87489968bf034a02786e61135029
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Tue Apr 16 17:18:53 2013 +0900

    EBookBackendSqliteDB: Avoid summary introspection on initial creation.
    
    The summary introspection does not introspect whether regular prefix
    indexes are created, which is acceptable since it does not effect queries.
    
    However since we introspect before creating the indexes, we lose the
    configured index information which is needed to initially create those
    indexes.
    
    This patch simply checks if the table exists when initially creating
    the summary and avoids the introspection if the table is being created
    for the first time.

 .../libedata-book/e-book-backend-sqlitedb.c        | 50 +++++++++++++++++++++-
 1 file changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c 
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 0a1ba71..e26d9bd 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -698,6 +698,47 @@ collect_columns_cb (gpointer ref,
        return 0;
 }
 
+static gint
+get_count_cb (gpointer ref,
+             gint n_cols,
+             gchar **cols,
+             gchar **name)
+{
+       gint64 count = 0;
+       gint *ret = ref;
+       gint i;
+
+       for (i = 0; i < n_cols; i++) {
+               if (g_strcmp0 (name[i], "count(*)") == 0) {
+                       count = g_ascii_strtoll (cols[i], NULL, 10);
+               }
+       }
+
+       *ret = count;
+
+       return 0;
+}
+
+static gboolean
+check_folderid_exists (EBookBackendSqliteDB *ebsdb,
+                      const gchar *folderid,
+                      gboolean *exists,
+                      GError **error)
+{
+       gboolean success;
+       gint count = 0;
+       gchar *stmt;
+
+       stmt = sqlite3_mprintf ("SELECT count(*) FROM sqlite_master WHERE type='table' AND name=%Q;", 
folderid);
+
+       success = book_backend_sql_exec (ebsdb->priv->db, stmt, get_count_cb, &count, error);
+       sqlite3_free (stmt);
+
+       *exists = (count > 0);
+
+       return success;
+}
+
 static gboolean
 introspect_summary (EBookBackendSqliteDB *ebsdb,
                     const gchar *folderid,
@@ -847,8 +888,12 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
        gboolean success;
        gchar *stmt, *tmp;
        GString *string;
+       gboolean already_exists = FALSE;
+
+       success = check_folderid_exists (ebsdb, folderid, &already_exists, error);
+       if (!success)
+               return FALSE;
 
-       /* Construct the create statement from the summary fields table */
        string = g_string_new (
                "CREATE TABLE IF NOT EXISTS %Q ( uid TEXT PRIMARY KEY, ");
 
@@ -931,7 +976,8 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                g_free (tmp);
        }
 
-       if (success)
+       /* Dont introspect the summary if the table did not yet exist */
+       if (success && already_exists)
                success = introspect_summary (ebsdb, folderid, error);
 
        /* Create indexes on the summary fields configured for indexing */


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