How to show useful error messages from a database error callback in Phonegap?
- by Magnus Smith
Using Phonegap you can set a function to be called back if the whole database transaction or the individual SQL statement errors. I'd like to know how to get more information about the error.
I have one generic error-handling function, and lots of different SELECTs or INSERTs that may trigger it. How can I tell which one was at fault? It is not always obvious from the error message.
My code so far is...
function get_rows(tx) {
tx.executeSql("SELECT * FROM Blah", [], lovely_success, statement_error);
}
function add_row(tx) {
tx.executeSql("INSERT INTO Blah (1, 2, 3)", [], carry_on, statement_error);
}
function statement_error(tx, error) {
alert(error.code + ' / ' + error.message);
}
From various examples I see the error callback will be passed a transaction object and an error object. I read that .code can have the following values:
UNKNOWN_ERR = 0
DATABASE_ERR = 1
VERSION_ERR = 2
TOO_LARGE_ERR = 3
QUOTA_ERR = 4
SYNTAX_ERR = 5
CONSTRAINT_ERR = 6
TIMEOUT_ERR = 7
Are there any other properties/methods of the error object?
What are the properties/methods of the transaction object at this point?
I can't seem to find a good online reference for this. Certainly not on the Phonegap website!