diff --git a/extensions/permissions/nsPermissionManager.cpp b/extensions/permissions/nsPermissionManager.cpp index 1a652bef4222..118a1093fdb9 100644 --- a/extensions/permissions/nsPermissionManager.cpp +++ b/extensions/permissions/nsPermissionManager.cpp @@ -1572,8 +1572,58 @@ nsresult nsPermissionManager::InitDB(bool aRemoveFile) { // fall through to the next upgrade MOZ_FALLTHROUGH; + // Version 10 removes appId from moz_hosts. SQLite doesn't support the + // dropping of columns from existing tables. We need to create a temporary + // table, copy the data, drop the old table, rename the new one. case 9: { - rv = mDBConn->SetSchemaVersion(HOSTS_SCHEMA_VERSION); + rv = mDBConn->BeginTransaction(); + NS_ENSURE_SUCCESS(rv, rv); + + bool tableExists = false; + mDBConn->TableExists(NS_LITERAL_CSTRING("moz_hosts_v9"), &tableExists); + if (tableExists) { + NS_WARNING( + "The temporary database moz_hosts_v9 already exists, dropping " + "it."); + rv = mDBConn->ExecuteSimpleSQL( + NS_LITERAL_CSTRING("DROP TABLE moz_hosts_v9")); + NS_ENSURE_SUCCESS(rv, rv); + } + + rv = mDBConn->ExecuteSimpleSQL( + NS_LITERAL_CSTRING("CREATE TABLE moz_hosts_v9 (" + " id INTEGER PRIMARY KEY" + ",host TEXT" + ",type TEXT" + ",permission INTEGER" + ",expireType INTEGER" + ",expireTime INTEGER" + ",modificationTime INTEGER" + ",isInBrowserElement INTEGER" + ")")); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING( + "INSERT INTO moz_hosts_v9 " + "(id, host, type, permission, expireType, " + "expireTime, modificationTime, isInBrowserElement) " + "SELECT id, host, type, permission, expireType, expireTime, " + "modificationTime, isInBrowserElement FROM moz_hosts WHERE appId = " + "0")); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mDBConn->ExecuteSimpleSQL( + NS_LITERAL_CSTRING("DROP TABLE moz_hosts")); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mDBConn->ExecuteSimpleSQL( + NS_LITERAL_CSTRING("ALTER TABLE moz_hosts_v9 RENAME TO moz_hosts")); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mDBConn->SetSchemaVersion(10); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mDBConn->CommitTransaction(); NS_ENSURE_SUCCESS(rv, rv); }