I would like to encapsulate SQLite database commands in a 'DBManager' class. To read the data, I've written the following lines:
DBManager.prototype.readMyData = function(param1, param2) {
this.db.transaction(function(tx) {
tx.executeSql("SELECT * FROM myTable WHERE param1 <= ?",
[param1],
function(tx, result) {
var myData = [];
for (var i=0; i<result.rows.length; i++) {
var row = result.rows.item(i);
myData.push(row);
}
},
errorHandler);
});
return myData;
}
The Problem: If I call the method readMyData() the return command is executed before the transaction method and its inner stuff.
How can I handle it so that the return value of readMyData() isn't empty but holds the myData array?