From 829f3827f4d0855b7e03c02123bd6c64ad2c85d5 Mon Sep 17 00:00:00 2001 From: Geoff Lankow Date: Thu, 19 Jan 2012 22:13:03 +1300 Subject: [PATCH] Bug 719002 - Use a transaction when upgrading addon.sqlite's schema; r=Mossop --- .../mozapps/extensions/AddonRepository.jsm | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/toolkit/mozapps/extensions/AddonRepository.jsm b/toolkit/mozapps/extensions/AddonRepository.jsm index 9f89575da1f7..689baa08de00 100644 --- a/toolkit/mozapps/extensions/AddonRepository.jsm +++ b/toolkit/mozapps/extensions/AddonRepository.jsm @@ -1577,10 +1577,10 @@ var AddonDatabase = { } this.connection.executeSimpleSQL("PRAGMA locking_mode = EXCLUSIVE"); - if (dbMissing) - this._createSchema(); + // Any errors in here should rollback try { + this.connection.beginTransaction(); switch (this.connection.schemaVersion) { case 0: LOG("Recreating database schema"); @@ -1603,14 +1603,15 @@ var AddonDatabase = { "appMinVersion TEXT, " + "appMaxVersion TEXT, " + "PRIMARY KEY (addon_internal_id, num)"); - this._createIndices(); - this._createTriggers(); - this.connection.schemaVersion = DB_SCHEMA; + this._createIndices(); + this._createTriggers(); + this.connection.schemaVersion = DB_SCHEMA; case 3: break; default: return tryAgain(); } + this.connection.commitTransaction(); } catch (e) { ERROR("Failed to create database schema", e); this.logSQLError(this.connection.lastError, this.connection.lastErrorString); @@ -2196,10 +2197,7 @@ var AddonDatabase = { */ _createSchema: function AD__createSchema() { LOG("Creating database schema"); - this.connection.beginTransaction(); - // Any errors in here should rollback - try { this.connection.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " + "id TEXT UNIQUE, " + @@ -2262,13 +2260,6 @@ var AddonDatabase = { this._createTriggers(); this.connection.schemaVersion = DB_SCHEMA; - this.connection.commitTransaction(); - } catch (e) { - ERROR("Failed to create database schema", e); - this.logSQLError(this.connection.lastError, this.connection.lastErrorString); - this.connection.rollbackTransaction(); - throw e; - } }, /**