0

i am trying to insert array values into some table for sqlite. my arrays values are not inserted. i am strucked here that was i tried can you guide me in correct way here i am getting the response from axion json output. response.zonedetails is a array. for (var i = 0; i < response.zoneDetails.length; i++){

      console.log('hi i am ');
      console.log('for loop log',response.zoneDetails[i]);

        var zoneNmae = response.zoneDetails[i].zonename;
        var parentZoneId = response.zoneDetails[i].parentzoneid;
        var levelId = response.zoneDetails[i].levelid;
        var zoneId = response.zoneDetails[i].zoneid;

   await this.setState({zonename: zoneNmae});
   await this.setState({zoneId:zoneId});
   await this.setState({parentzoneid: parentZoneId });
   await this.setState({levelid:levelId});
   this.initZonesDB();
   //this.addZonesdetailsInfo(response.zoneDetails);
   this.addZonesdetailsInfo();

this is my response :"zoneDetails": [ { "zonename": "zone1", "zoneid": 1, "parentzoneid": 10, "levelid": "2" }, { "zonename": "zone2", "zoneid": 2, "parentzoneid": 10, "levelid": "2" },

i am unable to insert all values every time,it was inserting first array of 1st index values only [0]. can any one suggest me to insert all values in good way for react native.

3
  • i am trying to insert the array values in mysqlite , using react-native-sqlite-storage can any one guide me how to save the values in table. Commented Sep 13, 2019 at 12:56
  • my response was"zoneDetails": [ { "zonename": "zone1", "zoneid": 1, "parentzoneid": 10, "levelid": "2" }, { "zonename": "zone2", "zoneid": 2, "parentzoneid": 10, "levelid": "2" }, { "zonename": "zone3", "zoneid": 3, "parentzoneid": 10, "levelid": "2" }, Commented Sep 13, 2019 at 12:57
  • my code addZonesdetailsInfo() { this.initZonesDB().then((db) => { db.transaction((tx) => { tx.executeSql('INSERT INTO zoneDetailsinfo VALUES (?, ?, ?, ?)', [this.state.zonename,this.state.zoneid,this.state.parentzoneid,this.state.levelid]).then(([tx, results]) => { resolve(results); console.log("device data inserted"); }); }).then((result) => { this.closeDatabase(db); }).catch((err) => { console.log(err); });}).catch((err) => { console.log(err);});} Commented Sep 13, 2019 at 13:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.