I am trying to query some information that I insert in a table, which I created previously. The error is the following:
Object {message: "no such table: HorarioP (code 1): , while compiling: SELECT * FROM HorarioP", code: 0}
The code where I consult and want to display the information is as follows:
scheduleprof.js
Controller
mostrarHorarioProf.$inject = ['$scope', 'obtenerHorarioProf'];
function mostrarHorarioProf($scope, obtenerHorarioProf){
var Horariop;
obtenerHorarioProf.datosHorario().then(function(informacion){
Horariop = informacion;
console.log(Horariop);
$scope.horario = Horariop;
});
};
Service
obtenerHorarioProf.$inject = ['$cordovaSQLite'];
function obtenerHorarioProf($cordovaSQLite){
return {
datosHorario: function(){
var sqlConsulta, db, asignatura, asignaturas, horariop, l_horario, i, fila;
sqlConsulta = "SELECT * FROM HorarioP";
asignatura = {};
asignaturas = [];
db = $cordovaSQLite.openDB({ name: "unicesar.db" });
horariop = $cordovaSQLite.execute(db, sqlConsulta, []).then(function(resultado) {
l_horario = resultado.rows.length;
for(i=0 ; i<l_horario ; i++){
fila = resultado.rows.item(i);
asignatura = {
codigo: fila.Codigo,
grupo: fila.Grupo,
nombre: fila.Nombre,
creditos: fila.Creditos,
dia: fila.Dia,
hora: fila.Hora,
lugar: fila.Lugar
};
asignaturas.push(asignatura);
}
return asignaturas;
}, function (err) {
console.error(err);
});
return horariop;
}
};
};
I insert the table and the information when I make the request to the server to enter the application through the role of teacher or teacher.
crearTablaHorario_P = "CREATE TABLE IF NOT EXISTS HorarioP(Codigo text primary key, Grupo integer,\n\
Nombre text, Creditos integer, Dia text, Hora text, Lugar text,)";
guardarHorario_P = "INSERT INTO HorarioP(Codigo, Grupo, Nombre, Creditos, Dia, Hora, Lugar) \n\
VALUES(?,?,?,?,?,?,?)";
$cordovaSQLite.execute(db, crearTablaPerfil_P);
$cordovaSQLite.execute(db, crearTablaHorario_P);
for(i = 0; i < largo; i++){
$cordovaSQLite.execute(db, guardarHorario_P, [Horario[i].CodiAsig, Horario[i].Grupo, Horario[i].NombAsig,
Horario[i].Creditos, Horario[i].DiaAsig, Horario[i].HoraAsig, Horario[i].LugarAsig]);
}
Thanks in advance for any assistance.
It seems to me that the problem is that the Query to create the Table could not be executed, in fact I notice incorrect characters
\n\
in the query:and at the end of your script you have
,)";
, which is also wrong.For this reason the message indicates that said table is not found. Try correcting the query: