[evolution-data-server/openismus-work-3-8] EBookBackendSqliteDB: Bumped DB revision to version 8



commit 2621c2139fbc4d3edfcc3d231c643dedc28614c1
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Wed Aug 28 15:00:42 2013 +0200

    EBookBackendSqliteDB: Bumped DB revision to version 8
    
    Added code to upgrade DB schema and add missing data if the
    introspected revision is < 8.

 .../libedata-book/e-book-backend-sqlitedb.c        |   31 ++++++++++++++++++--
 1 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c 
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 63f1797..71c395d 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -59,7 +59,7 @@
 #endif
 
 #define DB_FILENAME "contacts.db"
-#define FOLDER_VERSION 7
+#define FOLDER_VERSION 8
 
 typedef enum {
        INDEX_PREFIX = (1 << 0),
@@ -1071,6 +1071,26 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                                g_string_append (string, ebsdb->priv->summary_fields[i].dbname);
                                g_string_append (string, "_localized TEXT, ");
 
+                               success = book_backend_sql_exec (
+                                       ebsdb->priv->db, string->str, NULL, NULL , error);
+
+                               g_string_free (string, TRUE);
+                       }
+               }
+               sqlite3_free (tmp);
+       }
+
+       /* If we're upgrading from < version 8, we need to add the _translit columns */
+       if (success && previous_schema >= 1 && previous_schema < 8) {
+
+               tmp = sqlite3_mprintf ("ALTER TABLE %Q ADD COLUMN ", folderid);
+
+               for (i = 1; i < ebsdb->priv->n_summary_fields && success; i++) {
+
+                       if (ebsdb->priv->summary_fields[i].type == G_TYPE_STRING &&
+                           ebsdb->priv->summary_fields[i].field != E_CONTACT_REV) {
+                               string = g_string_new (tmp);
+
                                g_string_append (string, ebsdb->priv->summary_fields[i].dbname);
                                g_string_append (string, "_translit TEXT, ");
 
@@ -1227,8 +1247,13 @@ create_contacts_table (EBookBackendSqliteDB *ebsdb,
                success = sqlitedb_set_locale_internal (ebsdb, lc_collate, error);
        }
 
-       /* Need to relocalize the whole thing if the schema has been upgraded to version 7 */
-       if (success && previous_schema >= 1 && previous_schema < 7) {
+       /* Need to relocalize the whole thing if the schema has been upgraded to version 7,
+        * also we need to enter all of the transliterated data for the '_translit' columns
+        * for any version below 8.
+        *
+        * So just re-enter all of the contacts if there is any upgrade to version 8.
+        */
+       if (success && previous_schema >= 1 && previous_schema < 8) {
                success = upgrade_contacts_table (ebsdb, folderid, current_region, lc_collate, error);
                relocalized = TRUE;
        }


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