This is my code
async function checksubsdetails() {
try {
let update_data = [];
db_office.query(
`SELECT arn_no,arn_id,cams_email from no_of_arn WHERE cams_email !=''`,
async (err, arn_rows) => {
if (err) throw err;
for (let inx of arn_rows) {
// console.log(inx.arn_no)
await db_office.query(
`SELECT arn_no from cams_subs WHERE arn_no='${inx.arn_no}'`,
async (err, subs_rows) => {
if (err) throw err;
// console.log(subs_rows)
if (subs_rows.length == 0) {
await db_office.query(
`INSERT INTO cams_subs(arn_id, arn_no) values('${inx.arn_id}', '${inx.arn_no}')`,
(err, my_cursor) => {
if (err) throw err;
console.log(("New Data Added for Arn no -> ", inx.arn_no));
update_data.push(inx);
}
);
} else {
console.log("Data Already Exists for arn no ->", inx.arn_no);
//console.log(("New Data Added for.lo"))
update_data.push(inx);
}
}
);
}
return [2, update_data];
}
);
} catch (err) {
console.log(err);
return [1, "Exception While adding Data to Cams Subs"];
}
}
I am returning [2, update_data] but getting undefined for update_data.
I am not able to figure out what to do to resolve this because the further processes can only occur after getting this value.
update_data is giving result in if-else statement I have written but I want it to return the update_data array after for loop.
Please help me out in this.
Thanks