[evolution-data-server/cursor-staging: 25/25] EBookBackendSqliteDB: Various bug fixes related to upgrades



commit d18232f6b36e9c9ce0fb262dcdd12ef1b9ce172f
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sat Oct 12 03:46:10 2013 +0200

    EBookBackendSqliteDB: Various bug fixes related to upgrades
    
      o Call introspect_summary() earlier, before ALTER TABLE and
        adding columns of auxilliary data based on fields which
        are in the summary.
    
      o Fetch the system locale if no locale is previously set in
        an existing DB (i.e. upgraded), fixes a case where we access
        a missing ECollator

 .../libedata-book/e-book-backend-sqlitedb.c        |   24 ++++++++++++-------
 1 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c 
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 75b5218..80f0e80 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -841,7 +841,7 @@ introspect_summary (EBookBackendSqliteDB *ebsdb,
                     const gchar *folderid,
                     GError **error)
 {
-       gboolean success;
+       gboolean success, have_attr_list;
        gchar *stmt;
        GList *summary_columns = NULL, *l;
        GArray *summary_fields = NULL;
@@ -928,6 +928,7 @@ introspect_summary (EBookBackendSqliteDB *ebsdb,
                goto introspect_summary_finish;
 
        ebsdb->priv->attr_list_indexes = 0;
+       ebsdb->priv->have_attr_list = have_attr_list = FALSE;
 
        if (multivalues) {
                gchar **fields = g_strsplit (multivalues, ":", 0);
@@ -939,7 +940,7 @@ introspect_summary (EBookBackendSqliteDB *ebsdb,
 
                        params = g_strsplit (fields[i], ";", 0);
                        field = e_contact_field_id (params[0]);
-                       iter = append_summary_field (summary_fields, field, NULL, NULL);
+                       iter = append_summary_field (summary_fields, field, &have_attr_list, NULL);
 
                        if (iter) {
                                for (j = 1; params[j]; ++j) {
@@ -958,6 +959,8 @@ introspect_summary (EBookBackendSqliteDB *ebsdb,
                        g_strfreev (params);
                }
 
+               ebsdb->priv->have_attr_list = have_attr_list;
+
                g_strfreev (fields);
        }
 
@@ -1053,6 +1056,10 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
 
        sqlite3_free (stmt);
 
+       /* Dont introspect the summary if the table did not yet exist */
+       if (success && already_exists)
+               success = introspect_summary (ebsdb, folderid, error);
+
        /* Now, if we're upgrading from < version 7, we need to add the _localized columns */
        if (success && previous_schema >= 1 && previous_schema < 7) {
 
@@ -1125,10 +1132,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 &&
@@ -1200,11 +1203,14 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
 
                lc_collate = stored_lc_collate;
 
-       } else if (success) {
-               /* When creating a new addressbook, default to system locale */
-               lc_collate = setlocale (LC_COLLATE, NULL);
        }
 
+       if (!lc_collate)
+               /* When creating a new addressbook, or upgrading from a version
+                * where we did not have any locale setting; default to system locale
+                */
+               lc_collate = setlocale (LC_COLLATE, NULL);
+
        /* Before touching any data, make sure we have a valid ECollator */
        if (success) {
                success = sqlitedb_set_locale_internal (ebsdb, lc_collate, error);


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