Page 2 of 7

Support for local SQLite datasources

Posted: Sun Sep 02, 2012 12:20 pm
by Rutger van Dijk

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++) { &#47;&#47; for each row
ourFinalArray&#46;push(results&#46;rows&#46;item(i)); &#47;&#47; pushing row object to an array
}
console&#46;log("first JSON: " + JSON&#46;stringify(ourFinalArray));
});

});

console&#46;log("second JSON: " + JSON&#46;stringify(ourFinalArray));
settings&#46;success(JSON&#46;stringify(ourFinalArray));

}
settings&#46;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.

Image


Support for local SQLite datasources

Posted: Mon Sep 03, 2012 12:39 am
by maxkatz

The database call is done asynchronously? Do you know if there a success callback available on which you would call settings.complete?


Support for local SQLite datasources

Posted: Mon Sep 03, 2012 7:54 am
by Rutger van Dijk

It works! I now have results from local database. The following code did it for me:

codevar db = window&#46;openDatabase("BMU", "", "BackMeUp", 1024*1000);

$t&#46;getCategoriesLocal = $t&#46;createClass(null, {

init: function(requestOptions) {
this&#46;__requestOptions = $&#46;extend({}, requestOptions);
},

process: function(settings) {
if (this&#46;requestOptions&#46;echo) {
settings&#46;success(this&#46;requestOptions&#46;echo);
} else {
var ourFinalArray = [];
db&#46;transaction(function(tx) {
tx&#46;executeSql('SELECT * FROM Categories', [], function(tx,results) {
var len = results&#46;rows&#46;length,
i;
for(i=0; i<len; i++) { &#47;&#47; for each row
ourFinalArray&#46;push(results&#46;rows&#46;item(i)); &#47;&#47; pushing row object to an array
}
settings&#46;success(JSON&#46;stringify(ourFinalArray));
settings&#46;complete('success');
});
});
}
}
});
/code


Support for local SQLite datasources

Posted: Mon Sep 03, 2012 8:02 am
by Rutger van Dijk

When one problem is solved, new question arrise ;)

I have read that it is possible to define input parameters also for a generic service. How to use them in the code above?


Support for local SQLite datasources

Posted: Mon Sep 03, 2012 8:04 am
by Rutger van Dijk

Hi Umesh,

At the moment I am trying to get a complete working solution. I am not good enough to make a generic solution, but of course I want to share the knowledge I got during the process. Maybe it is an idea if I create a tutorial for in the help section of Tiggzi.


Support for local SQLite datasources

Posted: Mon Sep 03, 2012 8:05 am
by maxkatz

Request parameters you define will be available in settings.data


Support for local SQLite datasources

Posted: Mon Sep 03, 2012 6:45 pm
by Unmesh Sheth

This would be fantastic. Let me give my background of work. I am building social enterprise which focuses on digitization (data collection) for many people who have frequently unreliable wireless and broadband connection. We need a truly reusable solution that I can use for many non-profit needs. Your tutorial will give me a great head start. My primary platform is based on Drupal which already have JQuery integration but Tiggzi based platform can help build rapid forms with off-line capability. For us affordability of mobile application with offline capability is a key. Thank you so much for taking a lead. Are you from Tiggzi or individual contributor? If you are from Tiggzi -- I can provide detailed specifications that can help our kind of application in future.


Support for local SQLite datasources

Posted: Tue Sep 04, 2012 10:35 am
by Rutger van Dijk

Working perfectly. Thanks.


Support for local SQLite datasources

Posted: Wed Jan 02, 2013 8:53 pm
by Jon

Hi all,

This is very encouraging to me: "We do have plans to add visual tools to make it simpler to work with such sources. It may be something like we have today for REST services."

I'm sure you're all busy after the move to the new HTML5 builder, but any projection on your development roadmap for when visual tools for local database integration will be implemented?

Much thanks,
Jon


Support for local SQLite datasources

Posted: Wed Jan 02, 2013 9:46 pm
by maxkatz

No ETA on this yet. MySQLite is no longer an active spec, the new one is called IndexedDB. You can always use IndexedDB API today, in JavaScript code.