Title: [185599] trunk/Source/WebKit2
Revision
185599
Author
beid...@apple.com
Date
2015-06-16 11:41:21 -0700 (Tue, 16 Jun 2015)

Log Message

IDB: Records table migration doesn't work with all versions of SQLite.
https://bugs.webkit.org/show_bug.cgi?id=145993

Reviewed by Darin Adler, provisionally reviewed by Jon Lee.

* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::v1RecordsTableSchema):
(WebKit::v1RecordsTableSchemaAlternate):
(WebKit::v2RecordsTableSchema):
(WebKit::v2RecordsTableSchemaAlternate):
(WebKit::createOrMigrateRecordsTableIfNecessary): Check both v1 and v1 Alternate whenever we check for the v1 schema.
  Ditto for the v2 schema. Crash all builds if the current schema is none of these.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (185598 => 185599)


--- trunk/Source/WebKit2/ChangeLog	2015-06-16 18:39:53 UTC (rev 185598)
+++ trunk/Source/WebKit2/ChangeLog	2015-06-16 18:41:21 UTC (rev 185599)
@@ -1,3 +1,18 @@
+2015-06-16  Brady Eidson  <beid...@apple.com>
+
+        IDB: Records table migration doesn't work with all versions of SQLite.
+        https://bugs.webkit.org/show_bug.cgi?id=145993
+
+        Reviewed by Darin Adler, provisionally reviewed by Jon Lee.
+
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+        (WebKit::v1RecordsTableSchema):
+        (WebKit::v1RecordsTableSchemaAlternate):
+        (WebKit::v2RecordsTableSchema):
+        (WebKit::v2RecordsTableSchemaAlternate):
+        (WebKit::createOrMigrateRecordsTableIfNecessary): Check both v1 and v1 Alternate whenever we check for the v1 schema.
+          Ditto for the v2 schema. Crash all builds if the current schema is none of these.
+
 2015-06-16  Dan Bernstein  <m...@apple.com>
 
         Build fix.

Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp (185598 => 185599)


--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp	2015-06-16 18:39:53 UTC (rev 185598)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp	2015-06-16 18:41:21 UTC (rev 185599)
@@ -54,20 +54,26 @@
 // Current version of the metadata schema being used in the metadata database.
 static const int currentMetadataVersion = 1;
 
+static const String v1RecordsTableSchema(const String& tableName)
+{
+    return makeString("CREATE TABLE ", tableName, " (objectStoreID INTEGER NOT NULL ON CONFLICT FAIL, key TEXT COLLATE IDBKEY NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE, value NOT NULL ON CONFLICT FAIL)");
+}
+
 static const String& v1RecordsTableSchema()
 {
-    static NeverDestroyed<WTF::String> v1RecordsTableSchemaString(ASCIILiteral(
-        "CREATE TABLE Records (objectStoreID INTEGER NOT NULL ON CONFLICT FAIL, key TEXT COLLATE IDBKEY NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE, value NOT NULL ON CONFLICT FAIL)"));
+    static NeverDestroyed<WTF::String> v1RecordsTableSchemaString(v1RecordsTableSchema("Records"));
     return v1RecordsTableSchemaString;
 }
 
+static const String& v1RecordsTableSchemaAlternate()
+{
+    static NeverDestroyed<WTF::String> v1RecordsTableSchemaString(v1RecordsTableSchema("\"Records\""));
+    return v1RecordsTableSchemaString;
+}
+
 static const String v2RecordsTableSchema(const String& tableName)
 {
-    StringBuilder builder;
-    builder.appendLiteral("CREATE TABLE ");
-    builder.append(tableName);
-    builder.appendLiteral(" (objectStoreID INTEGER NOT NULL ON CONFLICT FAIL, key TEXT COLLATE IDBKEY NOT NULL ON CONFLICT FAIL, value NOT NULL ON CONFLICT FAIL)");
-    return builder.toString();
+    return makeString("CREATE TABLE ", tableName, " (objectStoreID INTEGER NOT NULL ON CONFLICT FAIL, key TEXT COLLATE IDBKEY NOT NULL ON CONFLICT FAIL, value NOT NULL ON CONFLICT FAIL)");
 }
 
 static const String& v2RecordsTableSchema()
@@ -76,6 +82,12 @@
     return v2RecordsTableSchemaString;
 }
 
+static const String& v2RecordsTableSchemaAlternate()
+{
+    static NeverDestroyed<WTF::String> v2RecordsTableSchemaString(v2RecordsTableSchema("\"Records\""));
+    return v2RecordsTableSchemaString;
+}
+
 static int64_t generateDatabaseId()
 {
     static int64_t databaseID = 0;
@@ -140,14 +152,13 @@
     ASSERT(!currentSchema.isEmpty());
 
     // If the schema in the backing store is the current schema, we're done.
-    if (currentSchema == v2RecordsTableSchema())
+    if (currentSchema == v2RecordsTableSchema() || currentSchema == v2RecordsTableSchemaAlternate())
         return true;
 
-    // Currently the Records table should only be one of either the v1 or v2 schemas.
-    if (currentSchema != v1RecordsTableSchema()) {
-        ASSERT_NOT_REACHED();
-        return false;
-    }
+    // If the record table is not the current schema then it must be one of the previous schemas.
+    // If it is not then the database is in an unrecoverable state and this should be considered a fatal error.
+    if (currentSchema != v1RecordsTableSchema() && currentSchema != v1RecordsTableSchemaAlternate())
+        RELEASE_ASSERT_NOT_REACHED();
 
     SQLiteTransaction transaction(database);
     transaction.begin();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to