Hello, with a front end function called from an OnClick Events linked to a Process button, I load a csv file from my disk.
Then the following CodePostalInsertBatch function is called but my table remains desperately empty.
According to my log, the values of the variables cp, mun, reg are valid.
The log five.log(${inserted} lines inserted); displays “22 lines inserted” which should be ok.
Can you tell me what is wrong wih my function? Thank you!
Jean
function CodePostalInsertBatch(five, context, result) {
if (!context.batchData) {
return five.createError("Empty Chunk");
}
const lines = context.batchData.split(/\r?\n/);
const sql = `
INSERT INTO CodePostal (CodePostal, NomMunicipalite, CodeRegionAdm)
VALUES (?, ?, ?)
`;
let inserted = 0;
const db = five.getDatabaseConnectionByID('ErisiaDB');
const tx = five.startTransaction(db);
for (const line of lines) {
const cols = line.split(";").map(v => v.replace(/"/g, "").trim());
if (cols.length < 3) continue;
const cp = cols[0];
const mun = cols[1];
const reg = parseInt(cols[2]);
if (!cp || !mun || isNaN(reg)) continue;
//five.log(" " + cp + "-"+mun+"-"+reg);//values are OK
five.executeQuery(tx, sql, 0, cp, mun, reg);
inserted++;
}
five.commit(tx);
five.log(`${inserted} lines inserted`);
result.message = `${inserted} inserted`;
const verify = five.executeQuery("SELECT COUNT(*) AS nb FROM CodePostal");
five.log("Verification result: " + JSON.stringify(verify));
return five.success(result);
}


