Bug 14985 - Specify how autoincrement + empty keypath works
Specify how autoincrement + empty keypath works
Status: RESOLVED FIXED
Product: WebAppsWG
Classification: Unclassified
Component: Indexed Database API
unspecified
PC All
: P2 normal
: ---
Assigned To: This bug has no owner yet - up for the taking
public-webapps-bugzilla
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-11-29 00:23 UTC by Jonas Sicking
Modified: 2012-01-24 08:58 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonas Sicking 2011-11-29 00:23:34 UTC
What should happen for the following calls?

store = db.createObjectStore("mystore", { keyPath: "", autoIncrement: true });
store.add(1);           // store an item with key 1
store.add("foo");       // store an item with key "foo"
store.add({foo:"bar"}); // throw

It seems like if you have a objectStore with an empty keyPath and autoIncrement set to true, you'll either a valid key as the raw value, in which case that value is used as key. Or you'll specify an invalid key as value, in which case we should throw since it's not a valid key. In neither case would we actually use the key generator.

It seems to me that the simplest solution is to not allow an empty keyPath and autoIncrement set to true.

We would of course still allow no keypath and autoIncrement set to true. I.e. we'd still allow out-of-line keys together with autoIncrement. As well as non-empty keypaths with autoincrement set to true.
Comment 1 Jonas Sicking 2011-11-30 20:10:44 UTC
Fixed, made it throw.
Comment 2 Israel Hilerio [MSFT] 2012-01-13 01:01:11 UTC
Section 3.1.5 needs to be updated to reflect the fact that a valid key path can't be an empty string.  Currently it says:

"A valid key path is either the empty string, a JavaScript identifier, or multiple Javascript identifiers separated by periods"
Comment 3 Jonas Sicking 2012-01-24 08:58:20 UTC
Empty string is still a valid keyPath, at least for now. You just can't use an empty-string keyPath at the same time as you use a key generator since that is basically useless (see examples in comment 0).

The intent of this bug was just to cover the interaction between empty keypaths and autoincrement.

If we do end up killing empty keypaths that seems like a separate bug, so closing this for now. If we end up killing empty keypaths i'll open a new bug.

Feel free to reopen if you don't agree or if I'm misunderstanding something.