I have similar functions in my app that work just swimmingly. The thing that sets this apart is that I am passing a variable to the function to use as parameter in the WHERE clause of a SELECT.
The function is as follows:
function LoadSite(id) {
if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}
var selectStatement = 'SELECT * FROM site WHERE id = ?';
console.log('Select me:' + selectStatement);
console.log('Session id:' + id);
// this next section will select all the content from the site table as
// queried by the passed variable
db.transaction(function(transaction) { // ****!!!!****
transaction.executeSql(selectStatement, [id], function(transaction,
result) {
if (result != null && result.rows != null) {
for ( var i = 0; i < result.rows.length; i++) {
// load row into object
var row = result.rows.item(i);
var location = row.id + ' ' + row.site_id + ' ' +
row.address + ' ' + row.city + ' ' + row.state + ' ' + row.zip;
$('#lbWhere').append(location);
console.log(location);
}
}
}, errorHandler);
}, errorHandler, nullHandler);
return;
};
The issue is that I am getting an "Uncaught TypeError: Cannot call method 'transaction' of undefined..." (at the line with the ****!!!!**** above, where I have the closure db.transaction(function(transaction)) when the application fires in the console output. I assume that something is wrong with my SELECT statement, but for the life of me, I cannot figure it out. All documentation on use of parameters in SQLite queries are for everything but SELECT, but I figured I could use the syntax of a DELETE with a WHERE clause just as easily.
Any ideas as to why this is choking?
Thanks very much in advance!
Greg--