lundi 7 décembre 2015

Unable to excute openDatabase for SQLite Plugin

I am building a hybrid application using HTML5, JS, CSS. In this application I am making use of SQLite plugin so that 500+ MB of data can be stored in the Android device (mostly a tab). This data will be pulled by the application from a back-end server and will be available to the user when application is offline. As an initial step the application design is simple and first step is to get the SQLite plugin working. I have done below steps till now to implement the SQLite plugin:

  1. Create cordova project and add the plugin using cordova plugin add io.litehelpers.cordova.sqlite
  2. In the deviceready function I have used the openDatabase function. However, my code stops working when it enters the DeviceReady function shown below:

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

    function onDeviceReady(){

        alert("On deviceready function called");//This alert is triggered
        var db = window.sqlitePlugin.openDatabase({name: "StoreTest.db"});//*****Code Execution STOPS from this line*****
        db.transaction(createTable, errorInCreate, successInCreate);
        function createTable(tx){
            alert("in createTable");//This alert is not triggered meaning the code is not executed
                 tx.executeSql('DROP TABLE IF EXISTS TestImages');

                 tx.executeSql('CREATE TABLE IF NOT EXISTS TestImages(imgdata TEXT)');

             }

        function errorInCreate(){
            alert("Error creating table: ");//+JSON.stringify(e));
        }

        function successInCreate(){
            alert("success creating table");
        }
    }

I have referred the below links for SQLite Plugin:

http://ift.tt/1O3yCJy

http://ift.tt/1YTFpLa

Application will be in use both in iOS and Android.

Can anyone please help locate the error in using SQLite plugin?

Thanks, Abhishek.

Aucun commentaire:

Enregistrer un commentaire