Changeset 92950 in webkit
- Timestamp:
- Aug 12, 2011, 1:51:14 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r92946 r92950 1 2011-08-10 Hans Wennborg <hans@chromium.org> 2 3 IndexedDB: Overwriting key in unique index should be possible 4 https://bugs.webkit.org/show_bug.cgi?id=65993 5 6 Reviewed by Tony Chang. 7 8 Test that it's possible to overwrite an object store record even if there 9 is a derived key for that record in an index with the unique flag set. 10 11 * storage/indexeddb/index-unique-expected.txt: 12 * storage/indexeddb/index-unique.html: 13 1 14 2011-08-11 Yuta Kitamura <yutak@chromium.org> 2 15 -
trunk/LayoutTests/storage/indexeddb/index-unique-expected.txt
r92364 r92950 35 35 transaction.objectStore('store').put({x: 1}, 'baz') 36 36 finalAddSuccess(): 37 transaction.objectStore('store').put({x: 1}, 'baz') 37 38 PASS successfullyParsed is true 38 39 -
trunk/LayoutTests/storage/indexeddb/index-unique.html
r92364 r92950 135 135 function finalAddSuccess() { 136 136 debug("finalAddSuccess():"); 137 done(); 137 138 // An overwrite should be ok. 139 request = evalAndLog("transaction.objectStore('store').put({x: 1}, 'baz')"); 140 request.onerror = unexpectedErrorCallback; 141 request.onsuccess = done; 138 142 } 139 143 -
trunk/Source/WebCore/ChangeLog
r92946 r92950 1 2011-08-10 Hans Wennborg <hans@chromium.org> 2 3 IndexedDB: Overwriting key in unique index should be possible 4 https://bugs.webkit.org/show_bug.cgi?id=65993 5 6 Reviewed by Tony Chang. 7 8 It should be possible to overwrite an object store record even if 9 there is a derived key for that record in an index with the unique flag set. 10 11 * storage/IDBBackingStore.h: 12 * storage/IDBIndexBackendImpl.cpp: 13 (WebCore::IDBIndexBackendImpl::addingKeyAllowed): 14 * storage/IDBIndexBackendImpl.h: 15 * storage/IDBLevelDBBackingStore.cpp: 16 (WebCore::IDBLevelDBBackingStore::keyExistsInIndex): 17 * storage/IDBLevelDBBackingStore.h: 18 * storage/IDBObjectStoreBackendImpl.cpp: 19 (WebCore::IDBObjectStoreBackendImpl::putInternal): 20 * storage/IDBSQLiteBackingStore.cpp: 21 (WebCore::IDBSQLiteBackingStore::keyExistsInIndex): 22 * storage/IDBSQLiteBackingStore.h: 23 1 24 2011-08-11 Yuta Kitamura <yutak@chromium.org> 2 25 -
trunk/Source/WebCore/storage/IDBBackingStore.h
r88358 r92950 82 82 virtual String getObjectViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&) = 0; 83 83 virtual PassRefPtr<IDBKey> getPrimaryKeyViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&) = 0; 84 virtual bool keyExistsInIndex(int64_t databaseid, int64_t objectStoreId, int64_t indexId, const IDBKey& ) = 0;84 virtual bool keyExistsInIndex(int64_t databaseid, int64_t objectStoreId, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey) = 0; 85 85 86 86 class Cursor : public RefCounted<Cursor> { -
trunk/Source/WebCore/storage/IDBIndexBackendImpl.cpp
r83443 r92950 159 159 } 160 160 161 bool IDBIndexBackendImpl::addingKeyAllowed( IDBKey* key)161 bool IDBIndexBackendImpl::addingKeyAllowed(const IDBKey* indexKey, const IDBKey* primaryKey) 162 162 { 163 163 if (!m_unique) 164 164 return true; 165 165 166 return !m_backingStore->keyExistsInIndex(m_databaseId, m_objectStoreBackend->id(), m_id, *key); 166 RefPtr<IDBKey> foundPrimaryKey; 167 bool found = m_backingStore->keyExistsInIndex(m_databaseId, m_objectStoreBackend->id(), m_id, *indexKey, foundPrimaryKey); 168 if (!found) 169 return true; 170 if (foundPrimaryKey->isEqual(primaryKey)) 171 return true; 172 return false; 167 173 } 168 174 -
trunk/Source/WebCore/storage/IDBIndexBackendImpl.h
r83443 r92950 59 59 bool hasValidId() const { return m_id != InvalidId; }; 60 60 61 bool addingKeyAllowed( IDBKey*);61 bool addingKeyAllowed(const IDBKey* indexKey, const IDBKey* primaryKey); 62 62 63 63 // Implements IDBIndexBackendInterface. -
trunk/Source/WebCore/storage/IDBLevelDBBackingStore.cpp
r92468 r92950 792 792 } 793 793 794 bool IDBLevelDBBackingStore::keyExistsInIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& key)794 bool IDBLevelDBBackingStore::keyExistsInIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey) 795 795 { 796 796 ASSERT(m_currentTransaction); 797 797 798 798 Vector<char> foundEncodedPrimaryKey; 799 if (findKeyInIndex(m_currentTransaction.get(), databaseId, objectStoreId, indexId, key, foundEncodedPrimaryKey)) 800 return true; 801 802 return false; 799 if (!findKeyInIndex(m_currentTransaction.get(), databaseId, objectStoreId, indexId, indexKey, foundEncodedPrimaryKey)) 800 return false; 801 802 decodeIDBKey(foundEncodedPrimaryKey.begin(), foundEncodedPrimaryKey.end(), foundPrimaryKey); 803 return true; 803 804 } 804 805 -
trunk/Source/WebCore/storage/IDBLevelDBBackingStore.h
r89948 r92950 68 68 virtual String getObjectViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&); 69 69 virtual PassRefPtr<IDBKey> getPrimaryKeyViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&); 70 virtual bool keyExistsInIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& );70 virtual bool keyExistsInIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey); 71 71 72 72 virtual PassRefPtr<Cursor> openObjectStoreCursor(int64_t databaseId, int64_t objectStoreId, const IDBKeyRange*, IDBCursor::Direction); -
trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp
r92364 r92950 227 227 Vector<RefPtr<IDBKey> > indexKeys; 228 228 for (IndexMap::iterator it = objectStore->m_indexes.begin(); it != objectStore->m_indexes.end(); ++it) { 229 RefPtr<IDBKey> key = fetchKeyFromKeyPath(value.get(), it->second->keyPath()); 230 if (!key) { 229 const RefPtr<IDBIndexBackendImpl>& index = it->second; 230 231 RefPtr<IDBKey> indexKey = fetchKeyFromKeyPath(value.get(), index->keyPath()); 232 if (!indexKey) { 231 233 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "The key could not be fetched from an index's keyPath.")); 232 234 return; 233 235 } 234 if ( key->type() == IDBKey::NullType) {236 if (indexKey->type() == IDBKey::NullType) { 235 237 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "One of the derived (from a keyPath) keys for an index is NULL.")); 236 238 return; 237 239 } 238 if (!i t->second->addingKeyAllowed(key.get())) {240 if (!index->addingKeyAllowed(indexKey.get(), key.get())) { // So problem is that if key() is the same as the old key for this record in this index, then we're not really *adding it*, just updating it... 239 241 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::CONSTRAINT_ERR, "One of the derived (from a keyPath) keys for an index does not satisfy its uniqueness requirements.")); 240 242 return; 241 243 } 242 indexKeys.append( key.release());244 indexKeys.append(indexKey.release()); 243 245 } 244 246 -
trunk/Source/WebCore/storage/IDBSQLiteBackingStore.cpp
r89948 r92950 676 676 } 677 677 678 bool IDBSQLiteBackingStore::keyExistsInIndex(int64_t, int64_t, int64_t indexId, const IDBKey& key)679 { 680 String sql = String("SELECT id FROM IndexData WHERE indexId = ? AND ") + whereSyntaxForKey( key);678 bool IDBSQLiteBackingStore::keyExistsInIndex(int64_t, int64_t, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey) 679 { 680 String sql = String("SELECT id FROM IndexData WHERE indexId = ? AND ") + whereSyntaxForKey(indexKey); 681 681 SQLiteStatement query(m_db, sql); 682 682 bool ok = query.prepare() == SQLResultOk; … … 684 684 685 685 query.bindInt64(1, indexId); 686 bindKeyToQuery(query, 2, key); 687 688 return query.step() == SQLResultRow; 686 bindKeyToQuery(query, 2, indexKey); 687 688 if (query.step() != SQLResultRow) 689 return false; 690 691 foundPrimaryKey = getPrimaryKeyViaIndex(0, 0, indexId, indexKey); 692 ASSERT(foundPrimaryKey); 693 return true; 689 694 } 690 695 -
trunk/Source/WebCore/storage/IDBSQLiteBackingStore.h
r89948 r92950 63 63 virtual String getObjectViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&); 64 64 virtual PassRefPtr<IDBKey> getPrimaryKeyViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&); 65 virtual bool keyExistsInIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& );65 virtual bool keyExistsInIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey); 66 66 67 67 virtual PassRefPtr<Cursor> openObjectStoreCursor(int64_t databaseId, int64_t objectStoreId, const IDBKeyRange*, IDBCursor::Direction);
Note:
See TracChangeset
for help on using the changeset viewer.