Bug 719002 - Use a transaction when upgrading addon.sqlite's schema; r=Mossop

This commit is contained in:
Geoff Lankow 2012-01-19 22:13:03 +13:00
parent 8fe41d5a99
commit 829f3827f4

View File

@ -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;
}
},
/**