Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite plugin dont work #22

Closed
PterPmnta opened this issue Apr 9, 2016 · 3 comments
Closed

SQLite plugin dont work #22

PterPmnta opened this issue Apr 9, 2016 · 3 comments

Comments

@PterPmnta
Copy link

I am trying to create a database and tables , but I want to do after the request to the server to be successful, I do not want to create it when you open the application , as I have seen they do in most examples of internet

I would also like to know whether to implement Project CrossWalk in my project , this causes or could be causing some sort of conflict with the SQLite plugin or with others.

Development Information

  • Crosswalk Plugin
  • Brackets editor
  • Windows 10
  • Cordova Cli 6.0.0
  • Ionic Cli 1.7.14
  • Node Version 5.5.0

This is my code

angular.module('unicesarApp', ['ionic', 'historialApp', 'ngCordova']) .controller('formulario', formulario) .service('obtenerDatos', obtenerDatos) .config(config);

 `formulario.$inject = ['$scope', 'obtenerDatos', '$state', '$timeout', '$cordovaSQLite'];

 function formulario($scope, obtenerDatos, $state, $timeout, $cordovaSQLite){

$scope.login = function(){


var datos, datosRespuesta;

datos = {
    Usuario: $scope.usuariotxt,
    Password: $scope.passwordtxt
};

if(datos.Usuario == undefined && datos.Password == undefined){

    $scope.respuesta = "Los campos estan vacios";

}else{                

    $scope.respuesta = "Solicitando informacion";

    obtenerDatos.Autenticacion(datos).then(function(response) {

      if(response.data) {

        datosRespuesta = response.data;

          if (datosRespuesta === "Usuario no registrado" || 
              datosRespuesta === "Contraseña incorrecta") {

                  $scope.respuesta = datosRespuesta;                              

          } else {        

                if (datosRespuesta.estudiante){

                    console.log(datosRespuesta.estudiante)

                    var db, Perfil, row, crearTablaPerfil, guardarPerfil, consultaPerfil; 

                    Perfil = datosRespuesta.estudiante;

                    db = $cordovaSQLite.openDB({ name: "unicesar.db" });

                    crearTablaPerfil = "CREATE TABLE IF NOT EXISTS Estudiante(Cedula integer primary key, Nombre text,   Apellido text, Rol integer, Facultad text, Programa text, Semestre integer)";

                    guardarPerfil = "INSERT INTO Estudiante(Cedula, Nombre, Apellido, Rol, Facultad, Programa, Semestre)  VALUES(?,?,?,?,?,?,?)";

                    consultaPerfil = "SELECT * FROM Estudiante";

                    $cordovaSQLite.execute(db, crearTablaPerfil);

                    $cordovaSQLite.execute(db, guardarPerfil, [Perfil.CeduEstu, Perfil.NombEstu, Perfil.ApelEstu,    Perfil.RolEstu, Perfil.FacuEstu, Perfil.ProgEstu, Perfil.Semestre]);

                    $cordovaSQLite.execute(db, consultaPerfil).then(function(result){

                        if(result.rows.length > 0) {

                            row = result.rows.item(0);

                            alert("Datos:", row.Cedula +" "+ row.Nombre +" "+ row.Apellido +" "+ row.Rol +" "+ row.Facultad +" "+ row.Programa +" "+ row.Semestre);


                $state.go('Loading');

                $timeout(function() {
                    $state.go(datosRespuesta.estudiante ? 'menuestu' : 'menuprof');
                }, 3000);

         }   

      } else {


            console.log(response.status);
            $scope.respuesta = "Error en la solicitud";
            //$state.go('login');

      };      

    });

};

};`

@brodycj
Copy link
Owner

brodycj commented Apr 28, 2016

I am trying to create a database and tables , but I want to do after the request to the server to be successful, I do not want to create it when you open the application , as I have seen they do in most examples of internet

This should be no problem, assuming that the deviceready event had been fired. If you have problems please start with a very simple test application and try one thing at a time until you see what causes the issue.

I would also like to know whether to implement Project CrossWalk in my project , this causes or could be causing some sort of conflict with the SQLite plugin or with others.

Problems with Crosswalk have been reported in the past, especially with the Android NDK libraries that are used by this project (ref: storesafe/cordova-sqlite-storage#336; storesafe/cordova-sqlite-storage#247; storesafe/cordova-sqlite-storage#235). A couple things you may want to try:

@PterPmnta
Copy link
Author

@brodybits i am blind, that problem was the path,

@jdnichollsc
Copy link

@brodybits Close the issue! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants