Page 3 of 7

Support for local SQLite datasources

Posted: Wed May 01, 2013 4:38 pm
by ApperyAmateur

Hi,

Could you tell me if there is any movement on REST services for local db. I have created an app with an online db but decided it needs to be local db instead. It has static content which does not need to be updated by the user.

From what I see above, SQLite and WebSQL are now not used (or not recommended) and I have read poor opinions of IndexedDB.

Could you recommend which I move forward with?

Thanks


Support for local SQLite datasources

Posted: Wed May 01, 2013 5:32 pm
by maxkatz

It wouldn't be a REST service. To access local databases you would be using their JavaScript API. So you could put the calls inside a Generic Service (described above in this post) and invoke it as any service within Appery.io.

Whether to use SQLite or IndexedDB -- depends on the app, what browsers you want to support, etc. There is a lot of information on the web.


Support for local SQLite datasources

Posted: Mon May 20, 2013 3:35 pm
by Dan Sweeney

Hello
I have the same problem where the settings.success is called before the array is filled. How did you fix this?
Thanks


Support for local SQLite datasources

Posted: Mon May 20, 2013 8:12 pm
by Kateryna Grynko

Hi Dan,

Sorry for the delay. Could you please give us JavaScript code for your Generic Service?


Support for local SQLite datasources

Posted: Tue May 21, 2013 8:01 am
by Dan Sweeney

Hi Katya, here it is:

var db = window.openDatabase("MELInsp", "1.0", "MEL Inspection DB", 200000);

$t.jsGetMyLocalInspections = $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 MyInspections', [], function(tx,results) {
alert(results.rows.length + ' records');
var len = results.rows.length,
i;
for(i=0; i);
}

});


Support for local SQLite datasources

Posted: Tue May 21, 2013 10:40 am
by Maryna Brodina

Hello! Could you post the entire code? Please use < code < / code tag


Support for local SQLite datasources

Posted: Tue May 21, 2013 10:53 am
by Dan Sweeney

Sorry, here it is:
codevar db = window&#46;openDatabase("MELInsp", "1&#46;0", "MEL Inspection DB", 200000);

$t&#46;jsGetMyLocalInspections = $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 MyInspections', [], function(tx,results) {
alert(results&#46;rows&#46;length + ' records');
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
}
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


Support for local SQLite datasources

Posted: Tue May 21, 2013 2:21 pm
by ApperyAmateur

I know this seems like a really basic question but my online db knowledge is limited.

The statement which includes ...'MELInsp' refers to the name of the database but how can I go about creating this database and what file extension does it have?

i've created db's through access and now created them on appery but I'm still unsure of how to store it offline

Does that make sense? :s


Support for local SQLite datasources

Posted: Tue May 21, 2013 4:36 pm
by Kateryna Grynko

Hi Dan,

Functions db.transaction and tx.executeSql are asynchronous. So you would need to move settings.success and settings.complete inside a function that is passed to tx.executeSql:
http://pastebin.com/Kmw2EUSK


Support for local SQLite datasources

Posted: Tue May 21, 2013 4:41 pm
by Kateryna Grynko

Hi Phil,

In this code, the database is created locally in the browser. That is, the data in the database is stored offline. Browser developer decides where the file is stored in the database. What is known is that the format of database is SQLite.