Error in SQLite IONIC 2


#1

IT’S RETURN CANNOT READ PROPERTY ‘executeSQL’ of undefined, in other page it’s work but in page orcamento.ts it’s got error

ionViewDidEnter(){
      this.database.buscaTipoeCliente()
      .then((data) => {
        this.tipovenda = data[0].tipovenda;
        this.database.presentToastError(this.tipovenda);
        this.tipodepreco = data[0].tipodepreco;
        this.database.presentToastError(this.tipodepreco);
      }, (error) => {
        this.database.presentToastError(JSON.stringify(error.message));
        this.database.presentToastError(JSON.stringify(error.status));
      });
     
    }
public buscaTipoeCliente(){
      return new Promise((resolve, reject) => {
      this.storage = new SQLite();
      this.storage.openDatabase({name: "infosysDB.db", location: "default"})
      .then(
        (success) => {
          this.storage.executeSql("SELECT * FROM preferencias", [])
          .then((data) => {
              if(data.rows.length > 0 ){
                data = [{"tipovenda": data.rows.item(0)['tipo'], "cliente": data.rows.item(0)['cliente'], "codigo": data.rows.item(0)['codigo'], "tipodepreco": data.rows.item(0)['tipodepreco']}]
                resolve(data);
              }else if(data.rows.length <= 0){
                data = "avista";
                resolve(data);
              }
            },
            (error) => {
              this.presentToastError(JSON.stringify(error.message + "database"));
              reject(error)
              console.log("não foi possivel carregar a tabela preferencias.");
          })
        },
        (error) => {
          reject(error);
          this.presentToast("Não foi possível abrir a base de dados!");
        });
        
      });
    }

#2

I’m baffled why you won’t just use ionic-storage, but if you insist on continuing to tilt at this windmill, make sure the platform is ready before trying to do anything with SQLite.


#3

are you trying to run the code on actual device or browser (ionic-lab)…because SQLite plugin will only work in actual mobile device not browsers just like cordova plugins.