Error with Sqlite db


#1

hai i am using sqlite db .I have created a db service as described in this link.but it shows an error
" Cannot call method ‘transaction’ of null" on self.db.transaction(function (transaction ".I am calling the init() function in $ionicPlatform ready.but db is showing as null.can anyone help how to fix that??


#2

I don’t know exactly why but if you are using new Cordova you need to specify location of SQLite DB. So you just need to pass location='default' to DB init function.


#3

my issue does not shows when i called the init function before performing any db change.I have called db.init() in $ionicPlatform ready.so why does it requires repeated db.init??

eg:
DbService.init().then(function(){
DbService.create(table);
});

where to pass location=‘default’

my init function is like this

var self = this;
self.db = null;

self.init =function(){
	  var def = $q.defer();
	  try{	  
		    if (window.cordova) {
    	      self.db = $cordovaSQLite.openDB({name: "demo.db"},function(){
    	    	  console.log("created SQlite DB");
    	        def.resolve(true);
    	      });
    	    }else{
    	    	self.db = window.openDatabase("demo.db", '1', 'demo', 1024 * 1024 * 100); // browser
    	    	  def.resolve(true);
    	    	//def.reject();
    	    }
	  }catch(e){
		  	def.reject(e);
	  }
	  return def.promise;
};

#4

should be:
$cordovaSQLite.openDB({name: “demo.db”, location: “default”}

As for init i don’t know, i don’t use ngCordova for SQLite.


#5

$cordovaSQLite.openDB({name: “demo.db”, location: “default”}

this worked…Thanks