IndexedDB: exception changes addendum

Showing 1-1 of 1 messages
IndexedDB: exception changes addendum Alec Flett 6/11/12 3:15 PM
Hi -
If you don't use IndexedDB, you can ignore this message. 

TL;DR: You can no longer call db.transaction() or db.setVersion() from inside a setVersion transaction. Its fairly rare for code to do this, but you may want to read on just in case.

This is an update to the earlier message about "Error/exception behavior changing" - The work there has uncovered a possibly more visible issue with our current implementation. I still suspect that nobody will be affected by this but I wanted to give a heads up just in case.

You can make these changes to your code today without waiting for the changes to land in Chrome.

Landing later this week in Chrome canary: you can no longer create any kind of transaction from inside a versionchange transaction, as a result of calling setVersion(). This will also apply when we (chrome) finishes transitioning to the spec-compliant onupgradeneeded system: you won't be allowed to create a new transaction from inside the versionchange transaction. Instead, you should create the transaction in the oncomplete handler for the versionchange transaction.

For example, if you had code that looked like this:

db.setVersion('3').onsuccess = function(version) {
   ...
   db.transaction('mystore', 'readwrite').onsuccess = populateDataStore;
}

This needs to be changed slightly to call populateDataStore after the end of the transaction:

db.setVersion('3').onsuccess = function(event) {
   var transaction = event.result;
   transaction.oncomplete = function() {
       db.transaction('mystore', 'readwrite').onsuccess = populateDataStore;
   };
}

The same is true if your code previously chained together setVersion calls:

db.setVersion('3').onsuccess = function(version) {
   ...
   db.setVersion('4').onsuccess = updateToVersion4;
}

This needs to be changed slightly to call populateDataStore after the end of the transaction:

db.setVersion('3').onsuccess = function(event) {
   var transaction = event.result;
   transaction.oncomplete = function() {
       db.setVersion('4').onsuccess = updateToVersion4;
   };
}

Please update to this pattern as soon as you can, so that nobody breaks when this lands. 

Let me know if you have any questions,

Alec