So my problem is how can I get all the data from the child table using the rowid of my parent table , problem here is after query the 1st row id I can see an output but then the next rowid will say
undefined is not an object (evaluating ‘res.rows.item(z)’)
here is my code
selectSQL(){
console.log("Reloading all data");
this.sqlite.create({
name: 'ionicdb.db',
location: 'default'
}).then((db: SQLiteObject) =>{
db.executeSql('SELECT * FROM carrots_expenses', {})
.then(res => {
console.log(res.message);
console.log("Selecting all data executed! : ");
if(res.rows.length > 0){
for(let z=0; z < res.rows.length; z++){
console.log("Fetch id from carrots expenses : " +res.rows.item(z).rowid);
this.parent_id.push(res.rows.item(z).rowid);
console.log("Parent ID : " +this.parent_id[z]);
db.executeSql('SELECT * FROM carrots_calculated_values WHERE rowid = '+this.parent_id[z],{})
.then(res => {
console.log("Fetch data from carrots_calculated_values");
this.dataRecord.push({id: res.rows.item(0).rowid ,cost: res.rows.item(0).cost_total , gain: res.rows.item(0).gain_total , money_return: res.rows.item(0).money_return , expected_Kilo: res.rows.item(0).expected_Kilo, expected_Price: res.rows.item(0).expected_Price});
console.log("Row id : " +res.rows.item(0).rowid+ " Cost : " +res.rows.item(0).gain_total);
}).catch(e=> console.log(e.message));
}}
}).catch(e=> console.log(e.message));
}).catch(e=> console.log(e.message));}
Where did I miss? or maybe suggestion on how to do it wisely
IONIC CLI V : 3.20.0
Sqlite cli v :5.6.0