W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2011

[indexeddb] Effects of calling Cursor.Update() on an existing Index

From: Israel Hilerio <israelh@microsoft.com>
Date: Tue, 12 Jul 2011 18:21:38 +0000
To: "public-webapps@w3.org" <public-webapps@w3.org>
CC: Jim Wordelman <jaword@microsoft.com>
Message-ID: <F695AF7AA77CC745A271AD0F61BBC61E3D191581@TK5EX14MBXC119.redmond.corp.microsoft.com>
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") {
                         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?

Israel
Received on Tuesday, 12 July 2011 18:22:18 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:46 GMT