0
votes

I'm trying to connect Phonegap 5.4 with SQLite on Android using SQLite-Plugin [https://github.com/litehelpers/Cordova-sqlite-storage]

Firstly, I create my project and navigate to it using Phonegap CLI

$phonegap create sqlite-demo
$cd sqlite-demo

After that, I ran this command to install SQLite plugin:

$phonegap plugin add https://github.com/litehelpers/Cordova-sqlite-storage --save

Finally, I used this below code to test [index.js file], but nothing happen:

var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);        
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
    app.receivedEvent('deviceready');
    var db = window.sqlitePlugin.openDatabase({name: "my.db"}, 
    function() {
        alert('Connected');
    },
    function(err) {
        alert('Error');
    });
},
// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}
};

On the PhoneGap API [http://docs.phonegap.com/plugin-apis/] site I don't see any section about Storage or Database.

Is there any solution?

1

1 Answers

0
votes

The solution is: just write your data manipulation code like this this, because the storage module is automatic injected in your project.