samedi 7 février 2015

Ionic and SQLite - Select rows from pre-filled database at start up

I'm trying to develop an app using the ionic framework, which should load a database, when the app starts up.


I'm tracking the process of the app, when I start it up, using logcat. It prints that the database is created, but all of the records are not visible in the log. I'm using Samsung Galaxy S3. You can see the code from app.js, where my issue is.


var religionerApp = angular.module('religioner', ['ionic','ngCordova']); var db = null; religionerApp.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("religioner.db", function(){ db = $cordovaSQLite.openDB("religioner.db"); }, function(error){ console.error("There was an error copying the database: " + error); db = $cordovaSQLite.openDB("religioner.db"); }); }); });



religionerApp.controller("ReligionerController", function($scope, $ionicPlatform, $cordovaSQLite){
$ionicPlatform.ready(function() {
$scope.tasks = [{title: "TEST"}];

var query = "SELECT overskrift FROM religioner";
$cordovaSQLite.execute(db, query, []).then(function(res){

if(res.rows.length > 0){
for(var i = 0; i < res.rows.length; i++){
$scope.tasks.push({title: res.rows.item(i).overskrift});
console.log("SELECTED -> " + res.rows.item(i).overskrift + " ");
}
}

else{
console.log("No results found");
}
}, function(err){
console.error(err);
});
});
});


The entire project is here: http://ift.tt/1FhPhV6


Thanks for reading.


Aucun commentaire:

Enregistrer un commentaire