Changeset 199120 in webkit


Ignore:
Timestamp:
Apr 6, 2016 3:25:37 PM (8 years ago)
Author:
beidson@apple.com
Message:

Modern IDB: Make sure SQLite backing store records have a INTEGER PRIMARY KEY column.
https://bugs.webkit.org/show_bug.cgi?id=156264

Reviewed by Alex Christensen.

No new tests (No testable change in behavior yet, current tests pass).

  • Modules/indexeddb/IDBKeyData.cpp:

(WebCore::IDBKeyData::encode): Fix the key name for backwards compatibility.
(WebCore::IDBKeyData::decode): Ditto.

  • Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:

(WebCore::IDBServer::v3RecordsTableSchema): Added v3 Records schema that includes a primary key column.
(WebCore::IDBServer::v3RecordsTableSchemaAlternate):
(WebCore::IDBServer::createOrMigrateRecordsTableIfNecessary): Upgrade to v3 instead of v2.
(WebCore::IDBServer::SQLiteIDBBackingStore::addRecord):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r199119 r199120  
     12016-04-06  Brady Eidson  <beidson@apple.com>
     2
     3        Modern IDB: Make sure SQLite backing store records have a INTEGER PRIMARY KEY column.
     4        https://bugs.webkit.org/show_bug.cgi?id=156264
     5
     6        Reviewed by Alex Christensen.
     7
     8        No new tests (No testable change in behavior yet, current tests pass).
     9
     10        * Modules/indexeddb/IDBKeyData.cpp:
     11        (WebCore::IDBKeyData::encode): Fix the key name for backwards compatibility.
     12        (WebCore::IDBKeyData::decode): Ditto.
     13
     14        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
     15        (WebCore::IDBServer::v3RecordsTableSchema): Added v3 Records schema that includes a primary key column.
     16        (WebCore::IDBServer::v3RecordsTableSchemaAlternate):
     17        (WebCore::IDBServer::createOrMigrateRecordsTableIfNecessary): Upgrade to v3 instead of v2.
     18        (WebCore::IDBServer::SQLiteIDBBackingStore::addRecord):
     19
    1202016-04-06  Simon Fraser  <simon.fraser@apple.com>
    221
  • trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp

    r197306 r199120  
    134134        return;
    135135
    136     encoder.encodeEnum("m_type", m_type);
     136    encoder.encodeEnum("type", m_type);
    137137
    138138    switch (m_type) {
     
    176176            || value == KeyType::Min;
    177177    };
    178     if (!decoder.decodeEnum("m_type", result.m_type, enumFunction))
     178    if (!decoder.decodeEnum("type", result.m_type, enumFunction))
    179179        return false;
    180180
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp

    r199078 r199120  
    110110}
    111111
     112static const String v3RecordsTableSchema(const String& tableName)
     113{
     114    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, recordID INTEGER PRIMARY KEY)");
     115}
     116
     117static const String& v3RecordsTableSchema()
     118{
     119    static NeverDestroyed<WTF::String> v3RecordsTableSchemaString(v3RecordsTableSchema("Records"));
     120    return v3RecordsTableSchemaString;
     121}
     122
     123static const String& v3RecordsTableSchemaAlternate()
     124{
     125    static NeverDestroyed<WTF::String> v3RecordsTableSchemaString(v3RecordsTableSchema("\"Records\""));
     126    return v3RecordsTableSchemaString;
     127}
     128
    112129static const String v1IndexRecordsTableSchema(const String& tableName)
    113130{
     
    202219        // If there is no Records table at all, create it and then bail.
    203220        if (sqliteResult == SQLITE_DONE) {
    204             if (!database.executeCommand(v2RecordsTableSchema())) {
     221            if (!database.executeCommand(v3RecordsTableSchema())) {
    205222                LOG_ERROR("Could not create Records table in database (%i) - %s", database.lastError(), database.lastErrorMsg());
    206223                return false;
     
    221238
    222239    // If the schema in the backing store is the current schema, we're done.
    223     if (currentSchema == v2RecordsTableSchema() || currentSchema == v2RecordsTableSchemaAlternate())
     240    if (currentSchema == v3RecordsTableSchema() || currentSchema == v3RecordsTableSchemaAlternate())
    224241        return true;
    225242
    226243    // If the record table is not the current schema then it must be one of the previous schemas.
    227244    // If it is not then the database is in an unrecoverable state and this should be considered a fatal error.
    228     if (currentSchema != v1RecordsTableSchema() && currentSchema != v1RecordsTableSchemaAlternate())
     245    if (currentSchema != v1RecordsTableSchema() && currentSchema != v1RecordsTableSchemaAlternate()
     246        && currentSchema != v2RecordsTableSchema() && currentSchema != v2RecordsTableSchemaAlternate())
    229247        RELEASE_ASSERT_NOT_REACHED();
    230248
     
    233251
    234252    // Create a temporary table with the correct schema and migrate all existing content over.
    235     if (!database.executeCommand(v2RecordsTableSchema("_Temp_Records"))) {
     253    if (!database.executeCommand(v3RecordsTableSchema("_Temp_Records"))) {
    236254        LOG_ERROR("Could not create temporary records table in database (%i) - %s", database.lastError(), database.lastErrorMsg());
    237255        return false;
    238256    }
    239257
    240     if (!database.executeCommand("INSERT INTO _Temp_Records SELECT * FROM Records")) {
     258    if (!database.executeCommand("INSERT INTO _Temp_Records (objectStoreID, key, value) SELECT objectStoreID, CAST(key AS TEXT), value FROM Records")) {
    241259        LOG_ERROR("Could not migrate existing Records content (%i) - %s", database.lastError(), database.lastErrorMsg());
    242260        return false;
     
    13071325    }
    13081326    {
    1309         SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("INSERT INTO Records VALUES (?, CAST(? AS TEXT), ?);"));
     1327        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("INSERT INTO Records VALUES (?, CAST(? AS TEXT), ?, NULL);"));
    13101328        if (sql.prepare() != SQLITE_OK
    13111329            || sql.bindInt64(1, objectStoreInfo.identifier()) != SQLITE_OK
Note: See TracChangeset for help on using the changeset viewer.