Error "no such table: tablename (code 1):, while compiling: Query", code: 0

3

I am trying to consult information that I insert in a table, which I created previously. The error is as follows:

Object {message: "no such table: HorarioP (code 1): , while compiling: SELECT * FROM HorarioP", code: 0}

The code where I consult and wish to show the information is the following:

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;            

    }

};

};

The table and information insert it 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 help.

    
asked by Pedro Miguel Pimienta Morales 16.05.2016 в 05:33
source

1 answer

3

It seems to me that the problem is that the Query could not be executed to create the Table, in fact I notice incorrect characters \n\ in the query:

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,)";

and at the end of your script you have ,)"; , which is also incorrect.

For this reason the message indicates that the table is not found. Try correcting the query:

crearTablaHorario_P = "CREATE TABLE IF NOT EXISTS HorarioP(Codigo text primary key, Grupo integer, Nombre text, Creditos integer, Dia text, Hora text, Lugar text)";
    
answered by 16.05.2016 / 16:16
source