- SDK Version:38
- Platforms(Android/iOS/web/all):IOS/android
var slctQUnit = `SELECT * FROM ${cUnitInfo.TABLE_NAME} WHERE ${cUnitInfo.UNIT_ID} = ?`;
var updQUnit = `UPDATE ${cUnitInfo.TABLE_NAME} SET ${cUnitInfo.PREVIOUS_METER_READING} =?,${cUnitInfo.PREVIOUS_METER_READING_DATE} =?,${cUnitInfo.CURRENT_METER_READING} =null,${cUnitInfo.CURRENT_METER_READING_DATE} =null,${cUnitInfo.IS_SYNC_SERVER} =0 WHERE ${cUnitInfo.UNIT_ID}=?`;
var istQUnit = `INSERT INTO ${cUnitInfo.TABLE_NAME} (${cUnitInfo.UNIT_ID},${cUnitInfo.PROJECT_ID},${cUnitInfo.UNIT_NO},${cUnitInfo.BLOCK},${cUnitInfo.METER_TYPE_ID},${cUnitInfo.PREVIOUS_METER_READING},${cUnitInfo.PREVIOUS_METER_READING_DATE},${cUnitInfo.IS_SYNC_SERVER}) VALUES (?,?,?,?,?,?,?,?)`;
for (var x = 0; x < data.metertypeid.length; x++) {
var bDbData = false;
var slctArgUnit = [data.unitid[x]];
var istArgUnit = [data.unitid[x], item.projectId, data.unit_no[x], data.block[x], data.metertypeid[x], data.previous_meter_reading_no[x], data.previous_meter_reading_date[x], 0];
var updArgUnit = [data.previous_meter_reading_no[x], data.previous_meter_reading_date[x], data.unitid[x]];
tx.executeSql(slctQUnit, slctArgUnit,
(tx, r1) => {
if(r1.rows.length >0){
tx.executeSql(istQUnit, istArgUnit,
(tx, rlst) => {
console.log("Insert unitInfo SUCCESS");
},
(tx, error) => {
console.log("Insert unitInfo FAIL" + error);
}
);
}else{
tx.executeSql(updQUnit, updArgUnit,
(tx, rlst) => {
console.log("Update unitInfo SUCCESS");
},
(tx, error) => {
console.log("Update unitInfo FAIL" + error);
}
);
}
console.log(r1);
},
(tx, e1) => {
console.log(e1);
}
);
}
I am trying to perform nested update transaction and insertion in select transaction. it cant seems to be work.