Bug 60720 - IndexedDB index does not enforce uniqueness
Summary: IndexedDB index does not enforce uniqueness
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-12 13:22 PDT by Mark Pilgrim (Google)
Modified: 2011-11-23 14:52 PST (History)
6 users (show)

See Also:


Attachments
test case (2.97 KB, text/html)
2011-05-12 13:23 PDT, Mark Pilgrim (Google)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Pilgrim (Google) 2011-05-12 13:22:52 PDT
Original test: http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_indexes.html?force=1

This is an adaptation of part of a test in Mozilla's IndexedDB test suite. It creates an object store with one record, then creates a unique index on one of the keys, then attempts to add another record with a duplicate key (which should violate that unique index). Mozilla correctly throws a CONSTAINT_ERR, but WebKit does not throw.
Comment 1 Mark Pilgrim (Google) 2011-05-12 13:23:13 PDT
Created attachment 93328 [details]
test case
Comment 2 Joshua Bell 2011-11-23 14:52:19 PST
The attached test is flawed - it's assuming that the index constraints are enforced synchronously during the add() operation and result in an exception being thrown. 

Per the spec, with the async API (which is what the test is using) the constraint is enforced asynchronously and the uniqueness constraint error is reported via the request object (i.e. the onerror handler will fire).

The test could be corrected with:

73d72
<     evalAndExpectException("objectStore.add({ name: 'Bob', height: 62, weight: 170 }, '237-23-7738');", "IDBDatabaseException.CONSTRAINT_ERR");
75c74,76
<     done();
---
>     req = evalAndLog("req = objectStore.add({ name: 'Bob', height: 62, weight: 170 }, '237-23-7738');", "IDBDatabaseException.CONSTRAINT_ERR");
>     req.onsuccess = unexpectedSuccessCallback;
>     req.onerror = done;

... but WebKit already has a test for this: LayoutTests/storage/indexeddb/index-unique.html