ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.09k stars 13.51k forks source link

Adding Crosswalk breaks SQLite plugin #6085

Closed PterPmnta closed 8 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');

              };      

            });

        };
     };
  };

Looking for something to help me solve the problem , I found a question asked in the forum of ionic existed people with the same problem

There is the link Crosswalk error

jgw96 commented 8 years ago

Hey! Thanks for opening an issue with us! So according to that forum post this issue was fixed by using this plugin https://github.com/litehelpers/Cordova-sqlite-storage#android-sqlite-implementation. Does that plugin not fix the issue for you? Thanks again!

PterPmnta commented 8 years ago

Sorry, but I still have doubts about the use and implementation of the version of this plugin

  1. This plugin litehelpers is the same that ngCordova plugin
  2. How implement this plugin with angular and ionic.
  3. How to install this plugin
dually8 commented 8 years ago

I'm using it like this for android.

// Opening the DB for android
var db = window.sqlitePlugin.openDatabase({
    name: "myDatabase.db",
    location: "default",
    androidDatabaseImplementation: 2,
    androidLockWorkaround: 1
});

// ...
// Example from http://ngcordova.com/docs/plugins/sqlite/
var query = "INSERT INTO test_table (data, data_num) VALUES (?,?)";
$cordovaSQLite.execute(db, query, ["test", 100]).then(function(res) {
    console.log("insertId: " + res.insertId);
}, function(err) {
    console.error(err);
});
jgw96 commented 8 years ago

Hello all! I am going to go ahead and close this issue as it is more of a question now instead of an issue. I would recommend that you visit our forum at https://forum.ionicframework.com and the awesome devs on there can help you with implementing sqllite on android (: Thanks everyone for using ionic!