So, I have an odd problem.
I’m working with an SQLite database through javascript in a web application.
I have a problem with a function that doesn’t get called. Here’s what I have:
var db = window.openDatabase("database", "1.0", "Database",
200000);
db.transaction(functionIUse, errorCB);
The above code doesn’t work. The functionIUse doesn’t get called. However if I do like this:
var db = window.openDatabase("database", "1.0", "Database",
200000);
alert('db open');
db.transaction(functionIUse, errorCB);
it suddenly gets called. Can anyone explain this behavior to me? It really has me puzzled.
Obviously I would also like to know how to make it work – Every time.
Thanks.
Your problem is definitely strange, but I think it has to do with your error callback.
To test this I created the the following jsfiddle
When you execute this JavaScript functionIUse gets called but functionIUse2 doesn’t and the only thing that is different is that errorCB exists but errorCBThatDoesntExists does not.
One thing I might recommend is using a JavaScript framework to help interact with the database like html5sql.js. It can make things much simpler by providing a framework to deal with the asynchronous nature of the HTML5 web database as well as providing clearer and more defined callbacks.