Reputation: 1630
I create an array:
var Detail:Array = new Array(getClass.detailArticle(brand, subgroup, name));
The method:
public function detailArticle(brand:String, subgroup:String, name:String):Array
{
var sqlConnection:SQLConnection;
sqlConnection = new SQLConnection();
sqlConnection.open(File.applicationStorageDirectory.resolvePath("assets/db.sqlite"));
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text =
"SELECT * FROM sen_updatesnew " +
"WHERE Brand= '" + brand + "' " +
"AND SubGroup= '" + subgroup + "' " +
"AND Name = '" + name + "' ";
stmt.execute();
var result:Array = stmt.getResult().data;
return result;
}
How to access the elements?
Detail["element"] or Detail[0] are not showing anything. The query is working by the way.
What am I doing wrong?
Upvotes: 0
Views: 126
Reputation: 39408
From the docs
If the responder argument is not null the specified Responder object designates methods that are called to handle the results of the operation. If the responder argument is null, in asynchronous execution mode a result event is dispatched if the operation is successful, or an error event is dispatched if the operation fails.
Since you have a null responder argument for the execute method, you will have to listen for the results in the result event. It sounds like you're trying to access the results before they are retrieved.
// make your result array an instance variable, not a functional local variable
protected var result:Array ;
// make this an instance variable so it can be accessed across methods
protected var stmt:SQLStatement = new SQLStatement();
// this can't return anything because there is nothing to return at the time this method completes it's execution
public function detailArticle(brand:String, subgroup:String, name:String):void
{
// some stuff
// add the event listener for the result event
stmt.addEventListener('result',onResult);
// other stuff
// no return statement
}
// the result handler
protected function onResult(event:SQLEvent):void{
result = stmt.getResult().data;
}
Upvotes: 2