Fix bug 328603 - Calendar sqlite database issues; renaming of storage.sdb. r=philipp
authorDaniel Boelzle [:dbo] <daniel.boelzle@sun.com>
Thu, 29 Jan 2009 10:05:54 +0100
changeset 1786 174fa863d99c3d41eae53ce03ceab098e5e065bb
parent 1785 f61570d094c528d85e8b6b4b7c9dfa1c1a25c4b0
child 1787 c01858f3a47b4203f990a688cc5450a3816aac17
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs328603
Fix bug 328603 - Calendar sqlite database issues; renaming of storage.sdb. r=philipp
calendar/base/src/calCalendarManager.js
--- a/calendar/base/src/calCalendarManager.js
+++ b/calendar/base/src/calCalendarManager.js
@@ -381,36 +381,37 @@ calCalendarManager.prototype = {
 
     checkAndMigrateDB: function calmgr_checkAndMigrateDB() {
         let dbService = Components.classes["@mozilla.org/storage/service;1"]
                                   .getService(Components.interfaces.mozIStorageService);
         db = dbService.openSpecialDatabase("profile");
 
         db.beginTransactionAs(Components.interfaces.mozIStorageConnection.TRANSACTION_EXCLUSIVE);
         try {
-            if (db.tableExists("cal_calendars")) {
-                // Check if we need to upgrade
+            if (db.tableExists("cal_calendars_prefs")) {
+                // Check if we need to upgrade:
                 let version = this.getSchemaVersion(db);
                 //cal.LOG("*** Calendar schema version is: " + version);
-
                 if (version < DB_SCHEMA_VERSION) {
                     this.upgradeDB(version, db);
-                } else if (version > DB_SCHEMA_VERSION) {
-                    db.rollbackTransaction();
-                    // Schema version is newer than what we know how to deal with.
-                    // Alert the user, and quit the app.
-                    this.alertAndQuit();
-                    return;
                 }
 
                 this.migrateDB(db);
 
                 db.executeSimpleSQL("DROP TABLE cal_calendars; " +
                                     "DROP TABLE cal_calendars_prefs; " +
                                     "DROP TABLE cal_calmgr_schema_version;");
+            }
+
+            if (!db.tableExists("cal_calendars")) {
+                // create dummy cal_calendars, so previous versions (pre 1.0pre) run into the schema check:
+                db.createTable("cal_calendars", "id INTEGER");
+                // let schema checks always fail, we cannot take the shared cal_calendar_schema_version:
+                db.createTable("cal_calmgr_schema_version", "version INTEGER");
+                db.executeSimpleSQL("INSERT INTO cal_calmgr_schema_version VALUES(" + (DB_SCHEMA_VERSION + 1) + ")");
                 db.commitTransaction();
             } else {
                 db.rollbackTransaction();
             }
         } catch (exc) {
             db.rollbackTransaction();
             throw exc;
         }