Mikhail Begoun
Posts: 0
Joined: Sun Mar 02, 2014 6:52 pm

Issue when working with Local DB

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

Mikhail Begoun
Posts: 0
Joined: Sun Mar 02, 2014 6:52 pm

Issue when working with Local DB

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

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

Issue when working with Local DB

Hello Mikhail.

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

Mikhail Begoun
Posts: 0
Joined: Sun Mar 02, 2014 6:52 pm

Issue when working with Local DB

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Issue when working with Local DB

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.

Mikhail Begoun
Posts: 0
Joined: Sun Mar 02, 2014 6:52 pm

Issue when working with Local DB

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...

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Issue when working with Local DB

Thank you for update! We'll review docs.

Return to “Issues”