IONIC 3 - sqlite3_step failure: can not rollback - no transaction is active

0

I have this error for a few days, if someone knows that it should be very much appreciated the help.

This apparently at the time of loading the storage.

    import {Injectable} from '@ angular / core';     import {Http, URLSearchParams} from '@ angular / http';     import 'rxjs / add / operator / map';

import { AlertController } from 'ionic-angular';

// IMPORT URL SERVICES
import { URL_SERVICES } from '../../config/url.services';

import { Platform } from 'ionic-angular';

import { ModalController } from 'ionic-angular'
import { LoginPage } from '../../pages/index.pages';

//pluguin storage
import { Storage } from '@ionic/storage';

@Injectable()
export class UsersProvider {

  token:string;
  id_user:string;

  constructor(public http: Http,
              private alertCtrl:AlertController,
              private platform:Platform,
              private storage:Storage,
              private modalCtrl:ModalController) {

              //aqui cargamos el storage, (falta el loading)
              this.load_storage();
            }

  //para validar si inicio session algun usuario y mostrar por ej el boton de salir
  activo():boolean{
    if( this.token ){
      return true;
    }else{
      return false;
    }
  }

  ingresar( email:string, password:string ){

    //PARA ENVIAR LOS DATOS
    let data = new URLSearchParams();

    //append para cade header a enviar
    data.append("email", email);
    data.append("password", password);

    //URL A LA CUAL HAREMOS EL POST
    let url = URL_SERVICES + '/login';

    //respuesta asincrona para poner un load
    //creamos un observador
    return this.http.post(url, data)
    .map( res=>{ //esta respuesta viene con codigo del error y los headers
      let data_res = res.json();
      console.log(data_res);

      //validamos si viene algun error
      if( data_res.err ){
        //creamos una alerta
        this.alertCtrl.create({
          title: "Error al Iniciar",
          subTitle: data_res.message,
          buttons: ["OK"]
        }).present();

      }else{
        //no vienen errores
        this.token = data_res.token;
        this.id_user = data_res.id_user;

        //GUARDAR STORAGE
        this.save_storage();

      }

    })//aqui deberia suscribirme porque es un observador, pero lo hare en otro lado
  }

  cerrar_session(){
    this.token = null;
    this.id_user = null;

    //guardar storage
    this.save_storage();

    this.modalCtrl.create(LoginPage)
    .present();
  }

  public save_storage(){

    console.log('entre a SAVE storage');

    if( this.platform.is("cordova") ){
      //dispositivo
      console.log('entre a SAVE storage DISPOSITIVO');
      this.storage.set('token', this.token);
      this.storage.set('id_user', this.id_user);
    }else{
      //computadora
      console.log('entre a SAVE storage COMPUTADORA');
      if( this.token ){
        localStorage.setItem("token", this.token);
        localStorage.setItem("id_user", this.id_user);
      }else{
        localStorage.removeItem("token");
        localStorage.removeItem("id_user");
      }
    }
  }

  public load_storage(){
    //esta es una promesa
    console.log('entre a CARGAR storage');
    let promesa = new Promise( ( resolve, reject )=>{

      if( this.platform.is("cordova") ){
        //dispositivo
        console.log('entre a CARGAR storage DISPOSITIVO');
        this.storage.ready().then( ()=>{

          this.storage.get("token").then( (token)=>{
            console.log('load storage', token);//prueba
            if( token ){
              this.token = token;
            }
          })

          this.storage.get("id_user").then( (id_user)=>{
            console.log('load storage', id_user);//prueba
            if( id_user ){
              this.id_user = id_user;
            }
            resolve();
          })

        })
      }else{
        //computadora
        console.log('entre a CARGAR storage PC');
        if( localStorage.getItem("token") ){

          this.token = localStorage.getItem("token");
          this.id_user = localStorage.getItem("id_user");
        }
        resolve();
      }

    });

    return promesa;

  }

}
    
asked by Edwin Anaya 05.11.2017 в 10:28
source

1 answer

1

I would not know how to answer you, because you would need to see more code.

But I can tell you what this mistake consists of.

You are trying to execute a transaction. A transaction is a set of modifications in the database that must be made ALL or NONE. That is, if a modification fails, so that the database does not stay halfway (which could produce problems of inconsistency, or half of the records remain), if the transaction is not completed, the database returns to the database. original point (rollback).

When a transaction is finished, a COMMIT must be executed so that all the changes made so far are recorded forever. If something has failed, a ROLLBACK must be executed that undoes all the changes made until the moment of the error.

But these two commands fail (an exception occurs) if a transaction has not been started. In your error, you are pretending to rollback when in reality, a transaction has not been started.

To start a transaction you must execute the sql command "BEGIN TRANSACTION", or using the methods of the SQLiteDataBase class, it would be a db.beginTransaction ().

Therefore, I would start looking at where in your code you are calling rollback, or at what point in the code you should initialize a transaction. Maybe it's some internal ionic method that you should keep in mind that it works with transactions.

    
answered by 05.11.2017 в 11:02