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.
I’m using for development:
-
Crosswalk Plugin
-
Brackets editor
-
Windows 10
-
Cordova Cli 6.0.0
-
Ionic Cli 1.7.14
-
Node Version 5.5.0
I found it Link
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');
};
});
};
};
};`
When install the apk in my smartphone the login view show me blank