EBookBackendSqliteDB: introspect summary structure before adding columns.
authorTristan Van Berkom <tristanvb@openismus.com>
Sat, 12 Oct 2013 18:54:55 +0000 (20:54 +0200)
committerTristan Van Berkom <tristanvb@openismus.com>
Wed, 23 Oct 2013 18:39:38 +0000 (20:39 +0200)
Some additional auxilary columns need to be added in upgrades, these
columns which need to be added depend on which contact fields are
in the summary. This patch ensures that the summary is properly
introspected before adding columns, so that the right columns are added.

addressbook/libedata-book/e-book-backend-sqlitedb.c

index 0898786..d20ec3f 100644 (file)
@@ -891,7 +891,7 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                        GError **error)
 {
        gint i;
-       gboolean success;
+       gboolean success = TRUE;
        gchar *stmt, *tmp;
        GString *string;
        gboolean already_exists = FALSE;
@@ -900,6 +900,14 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
        if (!success)
                return FALSE;
 
+       /* Introspect the summary if the table already exists */
+       if (already_exists) {
+               success = introspect_summary (ebsdb, folderid, error);
+
+               if (!success)
+                       return FALSE;
+       }
+
        string = g_string_new (
                "CREATE TABLE IF NOT EXISTS %Q ( uid TEXT PRIMARY KEY, ");
 
@@ -982,10 +990,6 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                g_free (tmp);
        }
 
-       /* 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 */
        for (i = 0; success && i < ebsdb->priv->n_summary_fields; i++) {
                if ((ebsdb->priv->summary_fields[i].index & INDEX_PREFIX) != 0 &&