1

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.

1
  • A solution I found to this myself, was to keep the javascript inline. But can't I have it in a separate file and make it work? Commented Nov 3, 2011 at 19:33

1 Answer 1

1

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

var errorCB = function(){
    alert("An Error Occured");
}
var functionIUse = function(transaction){
    alert('functionIUse Called');
}
var functionIUse2 = function(transaction){
    alert('functionIUse2 Called');
}
var db = window.openDatabase("database", "1.0", "Database", 200000);
alert('Database Has Been Opened');
db.transaction(functionIUse, errorCB);
db.transaction(functionIUse, errorCBThatDoesntExist);

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It looks like you're right. That's what I get for copy pasting. I didn't have the errorCB when I had the call in an external file. Also html5sql.js is going to save me a lot of time and work. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.