Return to Snippet

Revision: 43078
at March 16, 2011 07:43 by cmndo


Initial Code
function Query(sql_str, callback, args){
	yourDB.transaction(  
        function (transaction) {  
            transaction.executeSql(sql_str, [], function(transaction, results){
				callback(transaction, results, args);
			}, errorHandler);  
        }  
    ); 
}
//usage
Query("SELECT whatever FROM wherever", doBidding, {"extra":"awesome sauce"});

function doBidding(obj){
	alert(obj.extra);
}

Initial URL
http://www.digitalsurgeons.com

Initial Description
In a recent iphone webapp I developed, I needed to use safari's Local Database feature. The webapp needed to make a few SQL Queries while performing other actions.

The local database data transaction process makes it difficult to make queries and assign the data you really want. But hey, that's asynchronous event handling for you.

This function allows you to tightly couple an object with the query which will be available in the callback.

Initial Title
Query Local Database with targeted callback and custom arguements

Initial Tags
database, html5

Initial Language
JavaScript