Synchronous query in SQLite using Ionic



  • I have the following function:

    public requisicaoXPTA() {
      this.database.executeSql("SELECT * FROM tbl_xpta",
          []).then((data) => {
          // o resultado retorna aqu na variável data
    
      }, (error) => {
        console.log(error);    
    

    });
    }

    Qndo I will use this function I do this way:

    this.requisicaoXPTA();
    this.atualizar();

    Most often, the function atualizar() is executed before requisicaoXPTA(). I would like to perform the function atualizar() after having made the request in the table. What better way to do this synchronously?



  • You can pass a callback to be executed after the request, so:

    public requisicaoXPTA(callback) {
      this.database.executeSql("SELECT * FROM tbl_xpta", []).then((data) => {
        callback();
      }, (error) => {
        console.log(error);    
      });
    }
    

    The use would be like this

    this.requisicaoXPTA(this.atualizar);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2