Changeset 76126 in webkit


Ignore:
Timestamp:
Jan 19, 2011 8:24:05 AM (13 years ago)
Author:
hans@chromium.org
Message:

2011-01-19 Hans Wennborg <hans@chromium.org>

Reviewed by Jeremy Orlow.

IndexedDB: Support auto-increment keys
https://bugs.webkit.org/show_bug.cgi?id=52576

Add layout test for auto increment keys.
Update previous test not to consider auto increment an error.

  • storage/indexeddb/create-object-store-options-expected.txt:
  • storage/indexeddb/create-object-store-options.html:
  • storage/indexeddb/objectstore-autoincrement-expected.txt: Added.
  • storage/indexeddb/objectstore-autoincrement.html: Added.

2011-01-19 Hans Wennborg <hans@chromium.org>

Reviewed by Jeremy Orlow.

IndexedDB: Support auto-increment keys
https://bugs.webkit.org/show_bug.cgi?id=52576

Add support for auto-increment keys.

Test: storage/indexeddb/objectstore-autoincrement.html

  • storage/IDBDatabase.cpp: (WebCore::IDBDatabase::createObjectStore):
  • storage/IDBObjectStoreBackendImpl.cpp: (WebCore::genAutoIncrementKey): (WebCore::IDBObjectStoreBackendImpl::putInternal):
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r76125 r76126  
     12011-01-19  Hans Wennborg  <hans@chromium.org>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        IndexedDB: Support auto-increment keys
     6        https://bugs.webkit.org/show_bug.cgi?id=52576
     7
     8        Add layout test for auto increment keys.
     9        Update previous test not to consider auto increment an error.
     10
     11        * storage/indexeddb/create-object-store-options-expected.txt:
     12        * storage/indexeddb/create-object-store-options.html:
     13        * storage/indexeddb/objectstore-autoincrement-expected.txt: Added.
     14        * storage/indexeddb/objectstore-autoincrement.html: Added.
     15
    1162011-01-19  Csaba Osztrogonác  <ossy@webkit.org>
    217
  • trunk/LayoutTests/storage/indexeddb/create-object-store-options-expected.txt

    r72765 r76126  
    1818db.createObjectStore('b')
    1919db.createObjectStore('c', {autoIncrement: true});
    20 PASS Exception thrown
    21 PASS code is webkitIDBDatabaseException.UNKNOWN_ERR
    2220trans = db.transaction({mode: webkitIDBTransaction.READ_WRITE})
    2321PASS trans.mode is webkitIDBTransaction.READ_WRITE
  • trunk/LayoutTests/storage/indexeddb/create-object-store-options.html

    r72765 r76126  
    4545    evalAndLog("db.createObjectStore('b')");
    4646
    47     try {
    48         // FIXME: This should work in the future.
    49         debug("db.createObjectStore('c', {autoIncrement: true});");
    50         db.createObjectStore('c', {autoIncrement: true});
    51         testFailed('createObjectStore with autoIncrement = true should throw');
    52     } catch (err) {
    53         testPassed("Exception thrown");
    54         code = err.code;
    55         shouldBe("code", "webkitIDBDatabaseException.UNKNOWN_ERR");
    56     }
     47    debug("db.createObjectStore('c', {autoIncrement: true});");
     48    db.createObjectStore('c', {autoIncrement: true});
    5749
    5850    trans = evalAndLog("trans = db.transaction({mode: webkitIDBTransaction.READ_WRITE})");
  • trunk/Source/WebCore/ChangeLog

    r76122 r76126  
     12011-01-19  Hans Wennborg  <hans@chromium.org>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        IndexedDB: Support auto-increment keys
     6        https://bugs.webkit.org/show_bug.cgi?id=52576
     7
     8        Add support for auto-increment keys.
     9
     10        Test: storage/indexeddb/objectstore-autoincrement.html
     11
     12        * storage/IDBDatabase.cpp:
     13        (WebCore::IDBDatabase::createObjectStore):
     14        * storage/IDBObjectStoreBackendImpl.cpp:
     15        (WebCore::genAutoIncrementKey):
     16        (WebCore::IDBObjectStoreBackendImpl::putInternal):
     17
    1182011-01-19  Csaba Osztrogonác  <ossy@webkit.org>
    219
  • trunk/Source/WebCore/storage/IDBDatabase.cpp

    r72771 r76126  
    7474    // FIXME: Look up evictable and pass that on as well.
    7575
    76     if (autoIncrement) {
    77         // FIXME: Implement support for auto increment.
    78         ec = IDBDatabaseException::UNKNOWN_ERR;
    79         return 0;
    80     }
    81 
    8276    RefPtr<IDBObjectStoreBackendInterface> objectStore = m_backend->createObjectStore(name, keyPath, autoIncrement, m_setVersionTransaction.get(), ec);
    8377    if (!objectStore) {
  • trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp

    r75596 r76126  
    6060    , m_keyPath(keyPath)
    6161    , m_autoIncrement(autoIncrement)
     62    , m_autoIncrementNumber(-1)
    6263{
    6364    loadIndexes();
     
    7071    , m_keyPath(keyPath)
    7172    , m_autoIncrement(autoIncrement)
     73    , m_autoIncrementNumber(-1)
    7274{
    7375}
     
    114116
    115117    ASSERT((key->type() == IDBKey::StringType) != query.isColumnNull(0));
    116     // FIXME: Implement date.
     118    ASSERT((key->type() == IDBKey::DateType) != query.isColumnNull(1));
    117119    ASSERT((key->type() == IDBKey::NumberType) != query.isColumnNull(2));
    118120
     
    201203    RefPtr<IDBKey> key = prpKey;
    202204
    203     // FIXME: Support auto-increment.
    204 
    205     if (!objectStore->m_keyPath.isNull()) {
    206         if (key) {
    207             callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "A key was supplied for an objectStore that has a keyPath."));
     205    if (!objectStore->m_keyPath.isNull() && key) {
     206        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "A key was supplied for an objectStore that has a keyPath."));
     207        return;
     208    }
     209
     210    if (objectStore->autoIncrement() && key) {
     211        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "A key was supplied for an objectStore that is using auto increment."));
     212        return;
     213    }
     214
     215    if (objectStore->autoIncrement()) {
     216        key = objectStore->genAutoIncrementKey();
     217
     218        if (!objectStore->m_keyPath.isNull()) {
     219            // FIXME: Inject the generated key into the object.
     220            callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Adding data to object stores with auto increment and in-line keys not yet supported."));
    208221            return;
    209222        }
     223    } else if (!objectStore->m_keyPath.isNull()) {
    210224        key = fetchKeyFromKeyPath(value.get(), objectStore->m_keyPath);
     225
    211226        if (!key) {
    212             callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "The key could not be fetched from the keyPath."));
     227            callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "The key could not be fetched from the keyPath."));
    213228            return;
    214229        }
     
    217232        return;
    218233    }
     234
    219235    if (key->type() == IDBKey::NullType) {
    220236        callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "NULL key is not allowed."));
     
    512528}
    513529
     530PassRefPtr<IDBKey> IDBObjectStoreBackendImpl::genAutoIncrementKey()
     531{
     532    if (m_autoIncrementNumber > 0)
     533        return IDBKey::createNumber(m_autoIncrementNumber++);
     534
     535    String sql = "SELECT max(keyNumber) + 1 FROM ObjectStoreData WHERE objectStoreId = ? AND keyString IS NULL AND keyDate IS NULL";
     536
     537    SQLiteStatement query(sqliteDatabase(), sql);
     538    bool ok = query.prepare() == SQLResultOk;
     539    ASSERT_UNUSED(ok, ok);
     540
     541    query.bindInt64(1, id());
     542
     543    if (query.step() != SQLResultRow || query.isColumnNull(0))
     544        m_autoIncrementNumber = 1;
     545    else
     546        m_autoIncrementNumber = static_cast<int>(query.getColumnDouble(0));
     547
     548    return IDBKey::createNumber(m_autoIncrementNumber++);
     549}
     550
    514551
    515552} // namespace WebCore
  • trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.h

    r72771 r76126  
    8383    void loadIndexes();
    8484    SQLiteDatabase& sqliteDatabase() const;
     85    PassRefPtr<IDBKey> genAutoIncrementKey();
    8586
    8687    static void getInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl>, PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks>);
     
    104105    typedef HashMap<String, RefPtr<IDBIndexBackendImpl> > IndexMap;
    105106    IndexMap m_indexes;
     107    int m_autoIncrementNumber;
    106108};
    107109
Note: See TracChangeset for help on using the changeset viewer.