Changeset 65902 in webkit


Ignore:
Timestamp:
Aug 24, 2010 8:44:07 AM (14 years ago)
Author:
jorlow@chromium.org
Message:

2010-08-24 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Steve Block.

IndexedDB needs to manually delete all objectStore data and indexes
https://bugs.webkit.org/show_bug.cgi?id=44522

  • storage/indexeddb/objectstore-removeobjectstore-expected.txt: Added.
  • storage/indexeddb/objectstore-removeobjectstore.html: Added.
  • storage/indexeddb/resources/shared.js: (unexpectedSuccessCallback):

2010-08-24 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Steve Block.

IndexedDB needs to manually delete all objectStore data and indexes
https://bugs.webkit.org/show_bug.cgi?id=44522

Apparently it's only newer versions of SQLite that handle cascade
delete. The rest silently fail. So do it manually.

Test: storage/indexeddb/objectstore-removeobjectstore.html

  • storage/IDBDatabaseBackendImpl.cpp: (WebCore::IDBDatabaseBackendImpl::createObjectStore): (WebCore::doDelete): (WebCore::IDBDatabaseBackendImpl::removeObjectStore):
  • storage/IDBDatabaseBackendImpl.h:
  • storage/IDBFactoryBackendImpl.cpp: (WebCore::createTables):
  • storage/IDBObjectStoreBackendImpl.cpp: (WebCore::IDBObjectStoreBackendImpl::removeIndex):
  • storage/IDBObjectStoreBackendImpl.h: (WebCore::IDBObjectStoreBackendImpl::create): (WebCore::IDBObjectStoreBackendImpl::id):
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r65901 r65902  
     12010-08-24  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Steve Block.
     4
     5        IndexedDB needs to manually delete all objectStore data and indexes
     6        https://bugs.webkit.org/show_bug.cgi?id=44522
     7
     8        * storage/indexeddb/objectstore-removeobjectstore-expected.txt: Added.
     9        * storage/indexeddb/objectstore-removeobjectstore.html: Added.
     10        * storage/indexeddb/resources/shared.js:
     11        (unexpectedSuccessCallback):
     12
    1132010-08-24  Sam Weinig  <sam@webkit.org>
    214
  • trunk/LayoutTests/storage/indexeddb/resources/shared.js

    r65670 r65902  
    5252}
    5353
     54function unexpectedSuccessCallback()
     55{
     56    testFailed("Success function called unexpectedly.");
     57    debug("");
     58    verifySuccessEvent(event);
     59    done();
     60}
     61
    5462function unexpectedErrorCallback()
    5563{
  • trunk/WebCore/ChangeLog

    r65900 r65902  
     12010-08-24  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Steve Block.
     4
     5        IndexedDB needs to manually delete all objectStore data and indexes
     6        https://bugs.webkit.org/show_bug.cgi?id=44522
     7
     8        Apparently it's only newer versions of SQLite that handle cascade
     9        delete.  The rest silently fail.  So do it manually.
     10
     11        Test: storage/indexeddb/objectstore-removeobjectstore.html
     12
     13        * storage/IDBDatabaseBackendImpl.cpp:
     14        (WebCore::IDBDatabaseBackendImpl::createObjectStore):
     15        (WebCore::doDelete):
     16        (WebCore::IDBDatabaseBackendImpl::removeObjectStore):
     17        * storage/IDBDatabaseBackendImpl.h:
     18        * storage/IDBFactoryBackendImpl.cpp:
     19        (WebCore::createTables):
     20        * storage/IDBObjectStoreBackendImpl.cpp:
     21        (WebCore::IDBObjectStoreBackendImpl::removeIndex):
     22        * storage/IDBObjectStoreBackendImpl.h:
     23        (WebCore::IDBObjectStoreBackendImpl::create):
     24        (WebCore::IDBObjectStoreBackendImpl::id):
     25
    1262010-08-23  Sam Weinig  <sam@webkit.org>
    227
  • trunk/WebCore/storage/IDBDatabaseBackendImpl.cpp

    r65879 r65902  
    3333#include "SQLiteDatabase.h"
    3434#include "SQLiteStatement.h"
     35#include "SQLiteTransaction.h"
    3536
    3637#if ENABLE(INDEXED_DATABASE)
     
    142143    int64_t id = sqliteDatabase().lastInsertRowID();
    143144
    144     RefPtr<IDBObjectStoreBackendInterface> objectStore = IDBObjectStoreBackendImpl::create(this, id, name, keyPath, autoIncrement);
     145    RefPtr<IDBObjectStoreBackendImpl> objectStore = IDBObjectStoreBackendImpl::create(this, id, name, keyPath, autoIncrement);
    145146    ASSERT(objectStore->name() == name);
    146147    m_objectStores.set(name, objectStore);
    147     callbacks->onSuccess(objectStore.release());
     148    callbacks->onSuccess(objectStore.get());
    148149}
    149150
     
    155156}
    156157
     158static void doDelete(SQLiteDatabase& db, const char* sql, int64_t id)
     159{
     160    SQLiteStatement deleteQuery(db, sql);
     161    bool ok = deleteQuery.prepare() == SQLResultOk;
     162    ASSERT_UNUSED(ok, ok); // FIXME: Better error handling.
     163    deleteQuery.bindInt64(1, id);
     164    ok = deleteQuery.step() == SQLResultDone;
     165    ASSERT_UNUSED(ok, ok); // FIXME: Better error handling.
     166}
     167
    157168void IDBDatabaseBackendImpl::removeObjectStore(const String& name, PassRefPtr<IDBCallbacks> callbacks)
    158169{
    159     if (!m_objectStores.contains(name)) {
     170    RefPtr<IDBObjectStoreBackendImpl> objectStore = m_objectStores.get(name);
     171    if (!objectStore) {
    160172        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::NOT_FOUND_ERR, "No objectStore with that name exists."));
    161173        return;
    162174    }
    163175
    164     SQLiteStatement deleteQuery(sqliteDatabase(), "DELETE FROM ObjectStores WHERE name = ?");
    165     bool ok = deleteQuery.prepare() == SQLResultOk;
    166     ASSERT_UNUSED(ok, ok); // FIXME: Better error handling.
    167     deleteQuery.bindText(1, name);
    168     ok = deleteQuery.step() == SQLResultDone;
    169     ASSERT_UNUSED(ok, ok); // FIXME: Better error handling.
     176    SQLiteTransaction transaction(sqliteDatabase());
     177    transaction.begin();
     178    doDelete(sqliteDatabase(), "DELETE FROM ObjectStores WHERE id = ?", objectStore->id());
     179    doDelete(sqliteDatabase(), "DELETE FROM ObjectStoreData WHERE objectStoreId = ?", objectStore->id());
     180    doDelete(sqliteDatabase(), "DELETE FROM Indexes WHERE objectStoreId = ?", objectStore->id());
     181    // FIXME: Delete index data as well.
     182    transaction.commit();
    170183
    171184    m_objectStores.remove(name);
  • trunk/WebCore/storage/IDBDatabaseBackendImpl.h

    r65670 r65902  
    3636namespace WebCore {
    3737
     38class IDBObjectStoreBackendImpl;
    3839class IDBTransactionCoordinator;
    3940class SQLiteDatabase;
     
    7071    String m_version;
    7172
    72     typedef HashMap<String, RefPtr<IDBObjectStoreBackendInterface> > ObjectStoreMap;
     73    typedef HashMap<String, RefPtr<IDBObjectStoreBackendImpl> > ObjectStoreMap;
    7374    ObjectStoreMap m_objectStores;
    7475
  • trunk/WebCore/storage/IDBFactoryBackendImpl.cpp

    r65670 r65902  
    8989
    9090        "DROP TABLE IF EXISTS Indexes",
    91         "CREATE TABLE IF NOT EXISTS Indexes (id INTEGER PRIMARY KEY, objectStoreId INTEGER NOT NULL REFERENCES ObjectStore(id) ON DELETE CASCADE, name TEXT NOT NULL, keyPath TEXT, isUnique INTEGER NOT NULL)",
     91        "CREATE TABLE IF NOT EXISTS Indexes (id INTEGER PRIMARY KEY, objectStoreId INTEGER NOT NULL REFERENCES ObjectStore(id), name TEXT NOT NULL, keyPath TEXT, isUnique INTEGER NOT NULL)",
    9292        "DROP INDEX IF EXISTS Indexes_composit",
    9393        "CREATE UNIQUE INDEX IF NOT EXISTS Indexes_composit ON Indexes(objectStoreId, name)",
    9494
    9595        "DROP TABLE IF EXISTS ObjectStoreData",
    96         "CREATE TABLE IF NOT EXISTS ObjectStoreData (id INTEGER PRIMARY KEY, objectStoreId INTEGER NOT NULL REFERENCES ObjectStore(id) ON DELETE CASCADE, keyString TEXT, keyDate INTEGER, keyNumber INTEGER, value TEXT NOT NULL)",
     96        "CREATE TABLE IF NOT EXISTS ObjectStoreData (id INTEGER PRIMARY KEY, objectStoreId INTEGER NOT NULL REFERENCES ObjectStore(id), keyString TEXT, keyDate INTEGER, keyNumber INTEGER, value TEXT NOT NULL)",
    9797        "DROP INDEX IF EXISTS ObjectStoreData_composit",
    9898        "CREATE UNIQUE INDEX IF NOT EXISTS ObjectStoreData_composit ON ObjectStoreData(keyString, keyDate, keyNumber, objectStoreId)"
  • trunk/WebCore/storage/IDBObjectStoreBackendImpl.cpp

    r65893 r65902  
    260260    ASSERT_UNUSED(ok, ok); // FIXME: Better error handling.
    261261
     262    // FIXME: Delete index data as well.
     263
    262264    m_indexes.remove(name);
    263265    callbacks->onSuccess();
  • trunk/WebCore/storage/IDBObjectStoreBackendImpl.h

    r65667 r65902  
    4040class IDBObjectStoreBackendImpl : public IDBObjectStoreBackendInterface {
    4141public:
    42     static PassRefPtr<IDBObjectStoreBackendInterface> create(IDBDatabaseBackendImpl* database, int64_t id, const String& name, const String& keyPath, bool autoIncrement)
     42    static PassRefPtr<IDBObjectStoreBackendImpl> create(IDBDatabaseBackendImpl* database, int64_t id, const String& name, const String& keyPath, bool autoIncrement)
    4343    {
    4444        return adoptRef(new IDBObjectStoreBackendImpl(database, id, name, keyPath, autoIncrement));
     
    4646    ~IDBObjectStoreBackendImpl();
    4747
     48    int64_t id() const { return m_id; }
    4849    String name() const { return m_name; }
    4950    String keyPath() const { return m_keyPath; }
Note: See TracChangeset for help on using the changeset viewer.