Hopefully you can see a bit from the code what I’m trying to do here, basically I need to check if a record exists in a database, so I call a function to do so, but I’m using the sqlrunner class wherein the result of a query is called as an event response and I don’t know how to get that value out of the resulting function back to the parent.
I feel like I must be doing things backwards or something..
public function dbmatch(datetime:String, typecode:String):Boolean {
var q:String = "SELECT DateTime FROM Event WHERE DateTime='"+datetime+"' AND EventTypeCode='"+typecode+"'"
SQLService.getInstance().execute(q,null,matchresult);
function matchresult(result:SQLResult):Boolean{
var match:String = result.data[0];
if (match == null){return false} else {return true}
}
return matchresult();
}
elsewhere:
var recordexists:Boolean = dbmatch(datetime, "Gb");
if (!recordexists){...}
Basically the problem is that the SQLService class can’t immediatly return a result for your query. That is why it uses a callback listener function (matchresult in your example) to inform your program at a later time that it has finished the search.
A basic way of handling this would be to call the query, then wait for the Query to “callback” to your listening funciton, that can then continue execution.
Elsewhere: