1

In Firefox. Init (once)

var r, dbname = 'a1', db = mozIndexedDB;

First,

try { r = db.open(dbname, 5); } catch (ex) { console.log(ex); }
r.onupgradeneeded = r.onsuccess = r.onblocked = r.onerror = function (e) { console.log(e); };

you get two events fired as supposed to be. Then close the database,

r.result.close()

Finally, delete the database,

try { r = db.deleteDatabase(dbname); } catch (ex) { console.log(ex); }
r.onsuccess = r.onerror = r.onblocked = function (e) { console.log(e); };

deletes successfully. However when I start running the first step scrip (opening db), 'onupgradeneeded' does not get fired and opens database with version it had before it was deleted. Is it bug, or am I doing smth wrong?

Thanks.

David
  • 460
  • 2
  • 7
  • 17

1 Answers1

1

You don't seem to be doing anything wrong. For what it's worth, I believe the deleteDatabase implementation is relatively new in FF so perhaps you've found a bug.

One thing I would try is to first inspect and then physically remove the IndexeDB-backing .sqlite database files before restarting the browser. It could be a caching thing. Paths to those files below.

On a PC:

C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\<*>.default\indexedDB

On a Mac:

/Users/username/Library/Application\ Support/Firefox/Profiles/<*>.default/indexedDB/

The table in the .sqlite file that has the database version is called database, and there are two columns, name and version. Your database should be in that table and should list the version number.

Deleting the database should delete that row. If it doesn't, I believe you've found a bug.

Worst comes to worse, delete the entire directory in the indexedDB profile folder and reinstall to verify a fresh install works.

buley
  • 28,032
  • 17
  • 85
  • 106
  • 3
    Today I found out that it was me causing this strange behavior, not Firefox. I use sqlite db viewer which presumably locks the sqlite file and Firefox fails to reset the version. Whenever I exit my sqlite viewer, the code above (and my tests) start to work fine! Thought it is still weird that Firefox does not fire/throw no error. – David Jun 27 '12 at 21:30
  • Very interesting. Makes a lot of sense too. Thanks for reporting back, I'm sure others will run into this at some point as well as IDB picks up steam. – buley Jun 27 '12 at 21:54
  • 1
    Would be very appreciated if you could try to see if you are still seeing the same behavior. We should indeed be firing an "error" event. We've fixed some bugs since the initial implementation of deleteDatabase, possibly including this one. If you are still able to reproduce the error in a nightly build, please file a bug and I'll make sure it gets fixed. – Jonas Sicking Jul 15 '12 at 20:00