brodycj / cordova-sqlite-ext

A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/macOS/Windows with REGEXP (Android/macOS/iOS) and pre-populated databases (Android/iOS/macOS/Windows)
Other
72 stars 55 forks source link

SQLite plugin dont work #22

Closed PterPmnta closed 6 years ago

PterPmnta commented 8 years ago

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

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 commented 8 years ago

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: litehelpers/Cordova-sqlite-storage#336; litehelpers/Cordova-sqlite-storage#247; litehelpers/Cordova-sqlite-storage#235). A couple things you may want to try:

PterPmnta commented 8 years ago

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

jdnichollsc commented 8 years ago

@brodybits Close the issue! 👍