- From: Jonas Sicking <jonas@sicking.cc>
- Date: Tue, 12 Jul 2011 11:37:19 -0700
- To: Israel Hilerio <israelh@microsoft.com>
- Cc: "public-webapps@w3.org" <public-webapps@w3.org>, Jim Wordelman <jaword@microsoft.com>
On Tue, Jul 12, 2011 at 11:21 AM, Israel Hilerio <israelh@microsoft.com> wrote:
> Assuming you have the following records in an objectStore objStore:
>
> Record #1: {prop1: 1, prop2: "foo1"}
> Record #2: {prop1: 2, prop2: "foo2"}
> Record #3: {prop1: 3, prop2: "foo3"}
> Record #4: {prop1: 4, prop2: "foo4"}
>
> keyPath = "prop1"
>
> Now, we create an index on "prop2" called index1.
>
> Let's say get a cursor on index1 and we start iterating through it.
> When I get to Record #2, I decide to use the cursor index to call update and change prop2 to "foo5":
>
> var rq = objStore.index("index1").openCursor();
> rq.onsuccess = function (evt) {
> var cursor = evt.target.result;
> if (cursor) {
> if (cursor.value.prop1 == "foo2") {
I assume you mean cursor.value.prop2 here, right?
> var rq2 = cursor.update({prop1: 2, prop2: "foo5"});
> }
> cursor.continue();
> }
> };
>
> My question is what is going to happen to the cursor position when the update takes place?
>
> Our expectation is that the cursor value will remain unchanged in the client code while the database object entry (i.e. record) will change.
> This will produce the following values for cursor.key and cursor.primaryKey "foo2" and "2", respectively.
> Thus, we expect the cursor position to remain unchanged and continue() should return Record #3.
> Additionally, we expect to see the new Record #2 entry after Record #4.
>
> Do you agree?
Yes, this should be fully defined by the specification using the
cursor's internal "position" and "object store position" state in the
"steps for iterating a cursor".
I definitely agree that it would be nice to have some more readable
informal text that explains this, preferably in the form of a <p
class=note> somewhere in the cursor description.
For what it's worth this scenario happens not just through
cursor.update. If you change the cursor.update line in the code
snippet above to
objStore.put({prop1: 2, prop2: "foo5"});
or
objStore.delete(2);
objStore.add({prop1: 2, prop2: "foo5"});
the exact same situation arises, and the exact same behavior is
expected. Similarly, if the code is
objStore.delete(2);
or
cursor.delete();
this has the exact same behavior, except that it obviously doesn't
make the Record #2 appear after Record #4 while iterating.
/ Jonas
Received on Tuesday, 12 July 2011 18:38:15 UTC