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 ?
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);
}
}
I ehanced Myrne answer to add query parameters and a free context string :
function doQuery(tx, query, values, successHandler, context)
{
tx.executeSql(query, values, successHandler, errorHandler);
function errorHandler(transaction, error)
{
var text_context = context != undefined && context != "" ? "(" + context + ") " : "";
alert("Error "+text_context+": " + error.message + " in " + query + " (params : "+values.join(", ")+")");
}
}
This will return this kind of error :
Error (function update_commande) : could not prepare statement (1 no such column: field3) in UPDATE table SET field2 = ?, field3 = ? WHERE field1 = ? (params : 1.63, 1449, 606)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With