Rutger van Dijk
Posts: 0
Joined: Tue Aug 21, 2012 9:04 am

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++) { &#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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Support for local SQLite datasources

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

Rutger van Dijk
Posts: 0
Joined: Tue Aug 21, 2012 9:04 am

Support for local SQLite datasources

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

Rutger van Dijk
Posts: 0
Joined: Tue Aug 21, 2012 9:04 am

Support for local SQLite datasources

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?

Rutger van Dijk
Posts: 0
Joined: Tue Aug 21, 2012 9:04 am

Support for local SQLite datasources

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Support for local SQLite datasources

Request parameters you define will be available in settings.data

Unmesh Sheth
Posts: 0
Joined: Wed Jun 20, 2012 3:06 am

Support for local SQLite datasources

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.

Rutger van Dijk
Posts: 0
Joined: Tue Aug 21, 2012 9:04 am

Support for local SQLite datasources

Working perfectly. Thanks.

Jon
Posts: 0
Joined: Wed Dec 26, 2012 3:37 am

Support for local SQLite datasources

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Support for local SQLite datasources

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.

Return to “Issues”