Question

I have a simple function which returns an Array after getting data from SQLite Database. But, it returns undefined error.

To check about problem I used 3 alerts (alert 1, alert 2, alert 3). Logically there should be a sequence like alert 1 --> alert 2 --> alert 3, but sequence is alert 1 --> alert 3 --> alert 2.

It means it doesn't wait for getting data.

function farzigetType() {
    alert('alert 1');
    var arr = [];
    var qselecttype = "SELECT * FROM " + TABLE_OP_TYPE;;

    db.transaction(function (trans) {
        trans.executeSql(qselecttype, [],
            function (transaction, result) {

                if (result != null && result.rows != null) {
                    for (i = 0; i < result.rows.length; i++) {
                        var row = result.rows.item(i);    

                        person = new Object();
                        person.id = row.id;
                        person.op_val = row.op_val;
                        person.op_type = row.op_type;

                        arr.push(person);

                        //alert('select optype from'+TABLE_OP_TYPE+'=='+person.op_val+'--'+person.op_type);    
                    }

                    alert('alert 2');

                    return arr;    
                }
            }, errorHandler);
    }, errorHandler, nullHandler);    

    alert('alert 3');    
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top