I created a factory with a function that deliver a query for $cordovaSQLite.execute. I am sure that the query is correctly because I run that right in the database using SqliteBrowser in this works perfectly. In the console I have a message informing that the database was opened. But this function is not returning the data that I need. I received this error: prepare statement failed with error: 1 This is my code:
factotyDatabase.js
var app = angular.module('anotei');
app.factory('factoryDatabase', function($cordovaSQLite, $ionicLoading, $q){
var currentDB = undefined;
var DATABASE_NAME = 'anotei.db';
var PATH = 'anotei.db';
return{
init: function(){
if(currentDB == undefined){
currentDB = window.sqlitePlugin.openDatabase({
name: DATABASE_NAME,
createFromResources: PATH
});
}
return currentDB;
},
executeQuery: function(deliveredQuery, fields){
var defer = $q.defer();
$ionicLoading.show();
var resp = $cordovaSQLite.execute(currentDB, deliveredQuery, fields);
resp.then(
function(execution){
defer.resolve(execution);
$ionicLoading.hide();
},
function(error){
$ionicLoading.hide();
defer.reject(error);
console.log(error);
}
);
return defer.promise;
}
}
});
//This is the service with the function that calls the factory
var app = angular.module('anotei');
app.service('serviceSubject', function($q, factoryDatabase){
return{
getSubjects: function(){
var defer = $q.defer();
var resp = factoryDatabase.executeQuery('select * from materias');
resp.then(
function(resultSet){
var listMateria = [];
for(var i = 0; i < resultSet.rows.length; i++){
var materia = {};
materia.id_materia = resultSet.rows.item(i).id_materia;
materia.nome = resultSet.rows.item(i).nome;
materia.max_faltas = resultSet.rows.item(i).max_faltas;
materia.professor = resultSet.rows.item(i).professor;
materia.email_prof = resultSet.rows.item(i).email_prof;
materia.num_faltas = resultSet.rows.item(i).num_faltas;
listMateria.push(materia);
}
defer.resolve(listMateria);
},
function(error){
console.log(error);
}
);
return defer.promise;
}
}
});
Aucun commentaire:
Enregistrer un commentaire