This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 11976 - Autoincrement keys need to be cleaned up some in the spec
Summary: Autoincrement keys need to be cleaned up some in the spec
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: Indexed Database API (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: This bug has no owner yet - up for the taking
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
: 11947 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-02-03 21:12 UTC by Jeremy Orlow
Modified: 2011-03-08 03:14 UTC (History)
5 users (show)

See Also:


Attachments

Description Jeremy Orlow 2011-02-03 21:12:45 UTC
From the "[IndexedDB] Auto increment and spec inconsistency" thread:

On Mon, Jan 17, 2011 at 9:06 AM, Hans Wennborg <hans@chromium.org> wrote:
Reading http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html,
there seems to be some inconsistency around how an object store with
key generator is supposed to behave.

In 5.1 Object Store Storage Operation, step 1 it says: "If store uses
a key generator and key is undefined, set key to the next generated
key. If store also uses in-line keys, then set the property in value
pointed to by store's key path to the new value for key".

But in the object store example in 3.3.3, there is the following:

A second put operation will overwrite the record stored by the first
put operation.
var abraham = {id: 1, name: 'Abraham', number: '2107'};
store.put(abraham);

However, the way I read the specification, the key generator will
generate the key 2, and then set the "id" property in the value to 2.
So this operation does not at all overwrite the first record, and the
next statement in the example: "Now when the object store is read with
the same key, the result is different compared to the object read
earlier." is false.


It seems to me that for an object store with a key generator, it is
never possible to specify the key for a put or add operation: Using a
key parameter is disallowed (in 3.2.5 under "add" and "put"), and
in-line keys get overwritten.

This means that it is not possible to update a record with a put
operation if the object store uses a key generator, which seems
counter-intuitive to me.

To me, it would make sense that:

1. If a user provides an explicit key to an operation on an object
store that has a key generator, then the explicit key takes
precedence, and the key generator doesn't do anything.

2. If a user provides an in-line key, then that key takes precedence,
and the key generator doesn't do anything.
Comment 1 Hans Wennborg 2011-02-04 10:33:40 UTC
*** Bug 11947 has been marked as a duplicate of this bug. ***
Comment 2 Pablo Castro 2011-03-03 09:14:00 UTC
One more thing to cover: we should define the implications of indicating an explicit value on add() that overrides the key generator. If it's a non-numeric type there are probably no implications, but if it's a number I wonder if we should move the next number in the generator forward or not...if not it means that you have to careful and only add numeric keys that are really high to stores with generators or you risk conflicting with the generator and never being able to add an auto-numbered row again.
Comment 3 Jeremy Orlow 2011-03-03 09:42:38 UTC
(In reply to comment #2)
> One more thing to cover: we should define the implications of indicating an
> explicit value on add() that overrides the key generator. If it's a non-numeric
> type there are probably no implications, but if it's a number I wonder if we
> should move the next number in the generator forward or not...if not it means
> that you have to careful and only add numeric keys that are really high to
> stores with generators or you risk conflicting with the generator and never
> being able to add an auto-numbered row again.

Good point.  FWIW this is what we do in our implementation.
Comment 4 Jonas Sicking (Not reading bugmail) 2011-03-08 03:14:33 UTC
This was kind'a hairy to fix. Please let me know if the language is unclear. Especially first three steps in "steps for storing a record into an object store".

http://dvcs.w3.org/hg/IndexedDB/rev/bf74f973122d