Tuesday, January 25, 2011

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 http://nparashuram.com/trialtool/index.html#example=/ttd/IndexedDB/moz_indexedDB.html

4 comments:

RASG said...

hi.

i have a server hosting ASP pages and a client machine.

im testing your code at the client (FF4b9 + greasemonkey) while accessing the server.

the javascript halts and the console gives me the message 'security error', pointing to the line wich reads 'var request = window.indexedDB.open("BookShop-1");'.

any hints? could it be due to the 'window' object?

thanks.

Parashuram said...

@RASG, drop me a mail with details at http://nparashuram.com/contact.html and we can take it from there. I think this requires some more digging.

Shiby said...

Need a Help. The trial tool code s working correctly in my firefox 4, but the same piece of code in my program is not working. It says exception at the line where database is tried to be opened. The error is as follows :
Error: uncaught exception: [Exception... "The operation failed for reasons unrelated to the database itself and not covered by any other error code." code: "1" nsresult: "0x80660001 (NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR)"

Parashuram said...

@Shiby ... can you paste the code that you are using, or ping me at http://nparashuram.com/contact.html

Post a Comment