How to get the context of a Web Sql error?

Matthieu picture Matthieu · May 15, 2013 · Viewed 11.6k times · Source

I start deploying an offline application on iPhones, but it's still under heavy developpment. I have a simple error handler for my query :

db.transaction(tx) {
    tx.executeSql("SELECT * FROM TABLE",[], successHandler, errorHandler);
});
function errorHandler(transaction, error) {
    alert("Error : " + error.message);
}

When I test myself the application, and get an error, I manage to find what was the query generating the error. But when it's my users (distant users, of course), it's very difficult, as the error messages are not specific.

Is there a way to add context info to my error messages, for example the sql query, or a comment parameter ?

Answer

Myrne Stol picture Myrne Stol · May 15, 2013

You could use a pattern like this:

  db.transaction(tx) {
    doQuery(tx, "SELECT * FROM TABLE",[],theSuccessHandler)
  });

  function doQuery(tx, query, values, successHandler) {
    tx.executeSql(query, values, successHandler, errorHandler);
    function errorHandler(transaction, error) {
        alert("Error : " + error.message + " in " + query);
    }
  }