Refreshing IndexedDB Examples to FF 4 B9

The IndexedDB implementation in Firefox 4 Beta 9 had some interesting changes.

Event.result change
The biggest change was that for all IDBRequests, the result was available on the result. For example, the code snippet to get the cursor would be something like

var request = db.openCursor();
request.onsuccess = function(){ var cursor = event.result;}

This has changed to

var request = db.openCursor();
request.onsuccess = function(){ var cursor = result.result; }

I modified the examples in TrialTool to start using these changes appropriately.

Indexing Bug
The second interesting issue that I stumbled upon was about Indexes. I noticed that I was able to iterate over only the data that was added to the object store after the index was created. For some reason, data added before the index was created was not available on the index's cursor.

All IndexedDB data is stored using SQLite under the %profile%/IndexedDB. If you open the file using SQLite Browser, you would notice that all Indexed data is stored under a table called index_data. Opening this table confirms the fact that older data was not indexed.
I told Ben from Mozilla, and here is the bug tracking this.

Undefined Cursor
Another fact I stumbled upon was that the cursor was "undefined" when I try to open it on an empty database. I usually associate "undefined" to javascript properties that have not been initialized. Interestingly, the cursor is set to "undefined" after the iteration is complete, causing the confusion. I had a brief conversation with Jonas Sicking and suggested that setting it to null or false may be better. This is least disruptive and not break the existing way the end-of-iteration is checked using if (!cursor) {..handle end..}.

All the changes are not available at