Support for local SQLite datasources
Almost there. Currently I have created the REST to local db part. I will post later some new issue as I think I found some issue in Tiggzi, but it is working now.
Now looking at the Generic Service. I got everything working except one small part. Hopefully you have an idea how I can fix this?
code
var db = window.openDatabase("BMU", "", "BackMeUp", 1024*1000);
$t.getCategoriesLocal = $t.createClass(null, {
init: function(requestOptions) {
this.__requestOptions = $.extend({}, requestOptions);
},
process: function(settings) {
if (this.requestOptions.echo) {
settings.success(this.requestOptions.echo);
} else {
var ourFinalArray = [];
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM Categories', [], function(tx,results) {
var len = results.rows.length,
i;
for(i=0; i<len; i++) { // for each row
ourFinalArray.push(results.rows.item(i)); // pushing row object to an array
}
console.log("first JSON: " + JSON.stringify(ourFinalArray));
});
});
console.log("second JSON: " + JSON.stringify(ourFinalArray));
settings.success(JSON.stringify(ourFinalArray));
}
settings.complete('success');
}
});
/code
The code will create the correct output, the only problem is that 'settings.succes' is called before the array 'ourFinalArray' is filled with db content. You can see in attached screenshot that 'second JSON' is first with empty content.
Do you have an idea how I can fix this. It is the last stop before a great working online/offline app idea.