vendredi 25 mars 2016

Phonegap Cordova-sqlite-storage plugin not able to do select

I am building a Hybrid Phonegap application using Angular Kendo.
I am trying to use Cordova-sqlite-storage SQLite plugin in my Android application.

I have installed this plugin and I have below code:

.controller('sqlCtrl', ['$scope', '$window', function($scope, $window)
{
    document.addEventListener("deviceready", onDeviceReady, false);
    var myTestDb = null;

    // Cordova is ready
    function onDeviceReady() 
    {
        myTestDb = window.sqlitePlugin.openDatabase({name: "test.db", createFromLocation: 1, createFromResource: 1});
    };

     // Call this method from HTML button click 
    $scope.selectTable = function()
    {
        alert('selectTable called');

        myTestDb.transaction(function(transaction) 
        {
            var executeQuery = "SELECT * FROM testTable;";
            transaction.executeSql(executeQuery, [], 
            function(tx, result) 
            {
                alert("success");
                // Read table rows 
            },
            function(tx, error)
            {
                alert("Error:"+error.message);
            });
        });
    };
}]);

My database file is local and stored in www folder of the project.
I have confirmed that my db file is getting copied in assets/www of my Android application.

The problem that I am facing is:
1. How can I confirm call to "window.sqlitePlugin.openDatabase" is successful
2. When I call my function selectTable then nothing happens, only I get first alert message

I tried to fix 2nd problem by removing and adding plugin again, but nothings works.

Also what is the best way for debugging it, I am using windows machine and Android phone, how should I get console logs of my Phonegap application which running on Android device?

Aucun commentaire:

Enregistrer un commentaire