I'm trying to load an existent sqlite db into my ionic app.
I followed this guide http://ift.tt/1W7k7Yy
This is my code in app.js:
var app = angular.module('ionicApp', ['ionic', 'ngCordova']);
var db = null;
app.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
window.plugins.sqlDB.copy("comeInComoDB.db", function() {
db = $cordovaSQLite.openDB("comeInComoDB.db");
}, function(error) {
console.error("There was an error copying the database: " + JSON.stringify(error));
db = $cordovaSQLite.openDB("comeInComoDB.db");
});
var query = "SELECT MAX(visit_log_id) as visit_log_id_max, station_id, visit_ts FROM visit_log";
$cordovaSQLite.execute(db, query, []).then(function(res) {
if(res.rows.length > 0) {
for(var i = 0; i < res.rows.length; i++) {
console.log("SELECTED -> " + res.rows.item(i).station_id);
}
} else {
console.log("No results found");
}
}, function (err) {
console.error(JSON.stringify(err));
});
});
});
When I launch my app on android ionic run android -l -c
I get this:
796897 error Uncaught TypeError: Cannot read property 'transaction' of null, http://ift.tt/1W7k7YA, Line: 9
My sqlite DB is in www/comeInComoDB.db
Can you please help me?
Are there alternatives to load existent data from a db into my ionic app?
Thank you
Aucun commentaire:
Enregistrer un commentaire