Problem with global variable for db sqlite

Hello everybody, like the header, i have some issue with sqlite cordova. I declare a global variable

var db = null in app.js file

and create a factory AppDB in services.js like this:

.factory(‘AppDB’, function($cordovaSQLite, $localStorage){
var table = “statement create table”;
return {
initDB:function(){
db = $cordovaSQLite.openDB(“test.db”);
$cordovaSQLite.execute(db, table);
},
queryDB:function(){
// execute query statement
}
}

in initDB function, i open db successfully, but when i try to call queryDB, the db is null. I don’t understand why it happen.
Please help me. Thanks u.

Look at this post. It is thoroughly discussed there.

Thanks

Thank for your help. I get the answer from the blog blog.nraboy.com. The answer is so easy.