dspjm
dspjm

Reputation: 5850

Why I cannot use cordova-sqlite-storage?

I am writing an android app, I am using phonegap and with weinre for debugging.

Some info:

$ phonegap -v
5.3.9
$ cordova plugin list
cordova-plugin-whitelist 1.2.0 "Whitelist"
cordova-sqlite-storage 0.7.14 "Cordova sqlite storage plugin"

The plugin is installed, but when I run it with phonegap and open it in my phone, nothing shows up in the console. No error, nothing. The window object was printed in the console, but not everything else.

I am using the default configuration of phonegap, can anybody tell me why this is happenning?

This is the code I have written in my js script.

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady(event) {                              

    console.log(window);                                     
    //var db = window.sqlitePlugin.openDatabase({name: "my.db"});
    //var openDatabase = sqlitePlugin.openDatabase;          
    console.log(window.sqlitePlugin);                        
    console.log(window.sqlitePlugin.openDatabase);           

    var db = window.sqlitePlugin.openDatabase({name: "test.db"},
        function(db) {                                       
            console.log('db open succeeded');                
        },                                                   
        function(err) {                                      
            console.log('Open database ERROR: ' + JSON.stringify(err));
        }                                                    
    );                                                       

    db.executeSql("create table tmp 'column1' INT;", [], function (res) {
        console.log('got stringlength: ' + res.rows.item(0).stringlength);
    }, function(error) {                                     
        console.log('SELECT error: ' + error.message);       
    });                                                      

    db.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (res) {
        console.log('got stringlength: ' + res.rows.item(0).stringlength);
    }, function(error) {                                     
        console.log('SELECT error: ' + error.message);       
    });                                                      
}                                                            

Upvotes: 0

Views: 775

Answers (3)

Bogdan Mircea Stanciu
Bogdan Mircea Stanciu

Reputation: 222

in newer versions of the SQLite plugin location must be set when opening a database :

var db = window.sqlitePlugin.openDatabase({name: "my.db", location: "default"}); 

Upvotes: 0

IamKarim1992
IamKarim1992

Reputation: 646

Hi Kindly do something like this in your onDeviceReady(). Maybe it is unable to work with sqllite db .

onDeviceReady: function() {
        app.receivedEvent('deviceready');
          if(window.sqlitePlugin !== undefined) {
            console.log('opening sqlite DB ');
            db = window.sqlitePlugin.openDatabase("ECM_MOBILE");
        } else {
            console.log('opening Web SQL DB ');
            db = window.openDatabase("ECM_MOBILE", "1.0", "Cordova Demo", 200000);
        }   

    }

if sqlite is not being installed properly then , you need to fix the installation for sqlite db .

Upvotes: 0

Patrick Mueller
Patrick Mueller

Reputation: 697

I would suggest not using weinre, unless you really have to. Built-in alternatives for some devices, listed here: http://people.apache.org/~pmuellr/weinre/docs/latest/

Upvotes: 0

Related Questions