/ Published in: JavaScript
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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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); }
URL: http://www.digitalsurgeons.com