hi, it cannot be done because Apple followed HTML 5 specification: *** All queries must be part of a transaction (though the transaction may contain only a single query if desired). *** http://developer.apple.com/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/UsingtheJavascriptDatabase/chapter_4_section_4.html#//apple_ref/doc/uid/TP40007256-CH3-SW3 and in HTML5: The transaction() and readTransaction() methods takes one to three arguments. When called, these method must immediately return and then asynchronously run the transaction steps with the transaction callback being the first argument, the error callback being the second argument, if any, the success callback being the third argument, if any, and with no preflight operation or postflight operation. http://www.whatwg.org/specs/web-apps/current-work/multipage/structured-client-side-storage.html
if you somehow try to execute it synchronously you should get invalid state error per specification, your method could - instead of returning value - return callback which could set your value asynchronously, regards, Peter On Jan 27, 10:18 pm, Shu Chow <[email protected]> wrote: > Hi, I'm creating a javascript object and part of the job of it is to > abstract out the interaction with the Safari javascript database and > execute Sql. I have this method: > > getMessages: function() { > var container; > var transactionFunction = function (transaction) { > var successCallback = function(tx, result) { > //populate container > } > var errorCallback = function(tx, result) {} > transaction.executeSql('SELECT * FROM message', [], > successCallback, errorCallback); > } > this.systemDB.transaction(transactionFunction); > return container; > > } > > The problem is that since executeSql runs asynchronously, container is > never populated and the return statement returns undefined. In > xmlhttp calls, I can just force it to run synchronously and the return > value is fine. Is there a way to force executeSql to run > synchronously or design the function so that getMessages does actually > return the messages? Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en -~----------~----~----~----~------~----~------~--~---
