Cordova-sqlite-storage: Cannot read property 'transaction' of null

Created on 22 Mar 2017  路  2Comments  路  Source: storesafe/cordova-sqlite-storage

i am trying this plug-in with prepolulated database.

      window.plugins.sqlDB.copy("taskTree.db",0,function() {
            console.log("db read")
            db = $cordovaSQLite.openDB({name : 'taskTree.db',location : 'default'});
        }, function(error) {
            console.log("error in copy db",error.message)
            db = $cordovaSQLite.openDB({name: "taskTree.db",location: 'default'})
        })

            var val = [];
            $cordovaSQLite.execute(db, "SELECT * FROM nodeDetails").then(function(res) {
                console.log(res.rows.length);
                for (var i = 0; i < res.rows.length; i++) {
                   // $scope.val.push(res.rows.item(i).nodeName)
                    //console.log('added' + res.rows.item(i).firstname)
                }
            })

when i run this code i am getting the following error
sqlliteerror

i included the cardova file

   <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="js/ng-cordova.min.js"></script>


    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>
invalid question doc-todo doc-pitfall angular

All 2 comments

Service is running before app.run ?
workaround is to have a button to call a service

  $scope.loadDb = function(){
      console.log("load db");
      dbActionService.getNodes();
     }

and the factory is

taskTreeApp.factory('dbActionService',function($cordovaSQLite,$rootScope,$ionicPlatform){
    var nodeList = [];

    return {
        getNodes: function(){

             $ionicPlatform.ready(function() {
            if(angular.isDefined(db) && db !== null){
             $cordovaSQLite.execute(db, "SELECT nodeName FROM nodeDetails").then(function(res) {
                console.log(res.rows.length)
             }),function(err){
                console.log("error in reading the table"+err);
             }
            }else{
                console.log("error in service")
            }

        })
    }
    }
})

but that still doesn't solve my problem.
is there anyway to know the db load is completed ? or the problem with the service ?

You must use cordova-sqlite-ext for pre-populated databases.

Was this page helpful?
0 / 5 - 0 ratings