0

The way I get data is through a callback function [processclinicResults],

and it gives the array Collection to the value object _ClinicVO. enter image description here

I have a problem that I can not directly get the return arrayCollection through getTableContent function, I tried to return value after

enter image description here

but it returns null.

Does anyone know how to make it easy to get the array? I just don't want to declare the variables every time when I use the similar funciotn. Or I have to overwrite [clinicData]?

public function getTableContent( resultHandler:Function, faultHandler:Function = null ):void 
{
    var stmt:SQLStatement = new SQLStatement();
    stmt.sqlConnection = sqlConnection;
    stmt.text = 'SELECT * FROM Clinic;';
    stmt.itemClass = ClinicVO;
    stmt.addEventListener( SQLEvent.RESULT,
    function ( event:SQLEvent ):void {
        resultHandler.call( this, new ArrayCollection( stmt.getResult().data ) );
    });
    stmt.addEventListener( SQLErrorEvent.ERROR, faultHandler == null ? sqlErrorHandler : faultHandler );
    stmt.execute();
}

public function errorConnectingToTable(evt:SQLErrorEvent):void {
    trace("Error getting information from DB");
}

protected function processClinicResults(resultsArray:ArrayCollection=null):void {
    if (resultsArray == null) {
        trace("DB has NO data");
    //there is no data
    } else {
        clinicData = resultsArray;
    }
}
Pao
  • 21
  • 4
  • Since your callbacks are asynchronous (you use `addEventListener` on `stmt`, which implies this), you can't directly return a value via such a call. I think you should instead run queries server-side, request them via `URLRequest` and handle errors in there. – Vesper Apr 28 '14 at 08:50
  • I use adobe air to do the cross-platform task, the database and application are in the same device. The early version is like what you said--run queries on the view part and has it's drawbacks that it's too complicated. So I use [DAO-EXT](https://code.google.com/p/dao-ext/) that I could use MVC pattern to make my code more modular, but it apparently faces another problem though... – Pao Apr 28 '14 at 09:20

1 Answers1

-1

I could suggest you to use Flex ORM and responders to get access to your local DB as I do:

private var entityManager:EntityManager = EntityManager.instance;       
public var LocalDBSqlConnection:SQLConnection;      
LocalDBSqlConnection = new SQLConnection();
LocalDBSqlConnection.open(LocalDBFile);
public function loadClinic(responder:IResponder):void
    {                       
        var clinics:Array = entityManager.query("SELECT * FROM Clinic") as Array;
        responder.result(new ArrayCollection(clinics));                                 
    }

Somewhere call this:

loadClinic( new mx.rpc.Responder(onResult, onError));

Handelers:

private function onResult(data:Object):void
        {
            YourData = data as ArrayCollection;                         
        }
private function onError(info:Object):void
        {

        }

I'm sorry if it's not the way you are serching for=)

Ilyakom
  • 190
  • 1
  • 6
  • Thank you for your reply, so can I return the clinic array in the function loadClinic ? I'm not sure that the responder is a kind of callback function. – Pao Apr 28 '14 at 12:08