Reputation: 1956
I am using phonegap(cordova 2.1.0) for IOS/android app development. Every time i have to make a query to select or insert/update i am doing this:
//to insert username, password into db
var db = window.openDatabase(dbName, "1.0", gAppConfig.dbMessage, 200000);
db.transaction(queryUpdateURL, errorQuery);
function queryUpdateURL(tx)
{
var newURL = document.getElementById('changeServerURL').value ;
alert('new url='+newURL);
tx.executeSql("update "+gAppConfig.configTable+" set value='"+newURL+"' where key='serverURL'; ", queryUpdateSuccess, errorQuery);
return;
}
So, Is is necessary to open the db every time i execute a query or only once is enough. Then, if db opening is a success, 'queryUpdateURL' gets called and if the query given inside it is a success, 'queryUpdateSuccess' is called,else errorQuery function is called. SO, just make a single query, three functions are getting called. Is it the correct way/only way or any other workaround exists. This seems to be really painful, creating three functions for a single query. Any suggestions are most welcome. Thanks.
Upvotes: 0
Views: 1005
Reputation: 23273
Welcome to async programming. To reduce the number of method calls you need to make you can always save the "db" variable so you don't have to keep calling window.openDatabase. Other than that you will need to follow the transaction -> executeSql -> success or failure stack to get things added to your database.
Upvotes: 1