Why does data.rows.length return 0 when making an insert in a BD SQLite?

0

I'm having problems inserting data into a SQlite database on Ionic 2. basically I do not know if it's really inserting me.

This is the method of the creation I insert

  test = "prueba";
  initializeDatabase(){
    return this.sqlite.create({ name: 'data.db', location: 'default' }).then(db => {
        this.db = db;
        return this.db.executeSql(this.tabla_categorias,[]).then(data => {
            console.log("tabla categoria creada!");   
            return this.db.executeSql("INSERT INTO categorias (Nombre) values (?)",['prueba'])
            .then((data) =>{
              console.log("Datos insertados! : " +data.rows.item(0));
              if (data.rows.length > 0) {
                  return JSON.parse(data.rows.item(0).value);
              }
            }, (e)=>{
              console.log(JSON.stringify(e));
            });     
        }, err=>{
          console.log(' Error : ' + JSON.stringify(err));
        });
    }); 
  }

It is important to mention that you already use the following in the query.

 return this.db.executeSql("INSERT INTO categorias (Nombre) values ('prueba')",[])

 return this.db.executeSql("INSERT INTO categorias (Nombre) values (?)",['prueba'])

I'm debug with the browser in the console. and he throws this at me

Ionic Native: deviceready event fired after 8591 ms
SQLitePlugin.js:175 OPEN database: data.db
SQLitePlugin.js:179 OPEN database: data.db - OK
main.js:318 tabla categoria creada!
main.js:321 Datos insertados! : 0
main.js:517 Inicioundefined
main.js:617 ionViewDidLoad LoginPage

In inserted data, it always tells me 0

Someone who can guide me. the SQLite plugin if it is loading. but I'm not doing the insertion. Greetings.

    
asked by JuanL 25.02.2018 в 15:23
source

0 answers