Question

I've read several questions about this kind of problem, so I am aware of the purpose of onupgradeneeded, when it should be called and of the browser compatibility problems.

I am developing a web app that should support Chrome on Desktop and Safari on iOS. I am using the IndexedDB in Chrome, but implemented with the IndexedDBShim to fall back to WebSQL when I'm using mobile Safari.

The system all works fine in Chrome. In mobile Safari, the first time I load the page with no cached data, it will fail to create the database because onupgradeneeded is not called. However: if I reload the page, the second time it loads onupgradeneeded is called. From there, the shim works fine.

At the moment my fix is to show a warning asking the user to refresh the page - it then works.

What can I do that's better?

Was it helpful?

Solution

I also noticed this problem with the indexedDBShim. If you wait a few milliseconds it works correctly so maybe you can delay your code?

I know this isn't a perfect answer but this is the error which is happening:

"could not prepare statement (1 no such table: dbVersions)"

Somehow this error is hidden (a bug in the shim), as one of the maintainers I might look into it when I have time :).

This error occurs because this code is called a bit to soon (somewhere around line 1570):

tx.executeSql("SELECT * FROM dbVersions where name = ?", [name], function(tx, data){ 

This table doesn't exists yet because this code isn't executed yet (around line 1494):

tx.executeSql("CREATE TABLE IF NOT EXISTS dbVersions (name VARCHAR(255), version INT);", [], function(){

In short, there isn't much you can do about it because it is a bug in the shim, delaying the code is I think the only way to fix it on your side. Another possibility is fixing the shim, but that will take some more time I think.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top