Page 1 of 1

Issue when working with Local DB

Posted: Mon Mar 03, 2014 1:43 pm
by Mikhail Begoun

Hi,
i have build an app, and now trying simply add some row into local offline DB and then read it, but it doesn't work.

First, here's a handler for onDeviceReady = creating new db and populating a row

Next,
i am trying to read from this DB using custom service, listDB.js

When the last code is bind to the service - the application just freeze on load.
In debug mode i see that for listDB.js I see error 'window.openDatabase' is not a function.

Can you please help?

Thanks!
Mike


Issue when working with Local DB

Posted: Mon Mar 03, 2014 1:44 pm
by Mikhail Begoun

This is code for the onDeviceReady Handler
code
var db = window.openDatabase("Deep", "1.0", "Deep", 200000);
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS "in_queue" (name TEXT)');
tx.executeSql('INSERT INTO "in_queue" (name) VALUES ("First row")');

}, function(err) {
alert("Error processing SQL: "+err.code);
}, function () {
alert("success DB!");
}
);

/code

this code is for listDB.js
code
var db = window.openDatabase("Deep", "1.0", "Deep", 200000);

$t.getTableList = $t.createClass(null, {

Code: Select all

 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 "in_queue&quot',[], function(tx, results) {             

                // console.log("getTableList call made"); 
                 var len = results.rows.length,i; 

                 if (len == 0) { 
                  //donothing                         

                 } else { 
                     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("Tables: " + JSON&#46;stringify(ourFinalArray)); 
                     settings&#46;success(JSON&#46;stringify(ourFinalArray));                         

                 } 
                 settings&#46;complete('success'); 
             }); 
         }); 
     } 
 } 

});
/code

When the last code is bind to the service - the application just freeze on load.
In debug mode i see that for listDB.js I see error 'window.openDatabase' is not a function.

Can you please help?

Thanks!
Mike


Issue when working with Local DB

Posted: Mon Mar 03, 2014 2:21 pm
by Nikita

Hello Mikhail.

Are you testing it in a browser? SQL Lite works only on devices.


Issue when working with Local DB

Posted: Mon Mar 03, 2014 2:22 pm
by Mikhail Begoun

Hi Nikita, issue same on Android device. Progress bar just stuck on the screen during app load.


Issue when working with Local DB

Posted: Mon Mar 03, 2014 8:50 pm
by Maryna Brodina

Hello!

Code looks correct, but there are some notes...
1) replace $t with Appery
2) You can test in browser. Perhaps it won't work in all browsers, but it definitely works in Chrome. While testing in browser you have to use Load event instead Device ready.


Issue when working with Local DB

Posted: Tue Mar 04, 2014 7:19 am
by Mikhail Begoun

Thanks a lot, Maryna!
works fine on device! (doesn't work in Firefox).
as my code taken from Appery tutorial, it may make sense to update it as well.
http://docs.appery.io/tutorials/build...


Issue when working with Local DB

Posted: Tue Mar 04, 2014 12:57 pm
by Maryna Brodina

Thank you for update! We'll review docs.