Home > OS >  update query in sqlite failed
update query in sqlite failed

Time:08-24

I send my object by post request with postman then in the backend with node js recive it and update my table but it return sqlerror on string in object and no problem on integer ! 1 - my obj in postman => { "id" : 3, "controlsCode":123456, "controlsName" : "hamed" }

2 - my code in node => async editControls(req, res) {

try {
  const { id, controlsCode, controlsName } = req.body;

  const query = `update controls set controlCode=${controlsCode} , controlName=${controlsName} where id =${id}`;
  await sequelize
    .query(query)
    .then((item) =>
      this.response({ res, message: "ok", data: controlsCode })
    )
    .catch((error) => console.log(error.message));
} catch (error) {
  console.log(error.message);
}

}

3-error in node js => SQLITE_ERROR: no such column: hamed

CodePudding user response:

You need single quotes around the string literal:

try {
  const { id, controlsCode, controlsName } = req.body;

  const query = `update controls set controlCode=${controlsCode} , controlName='${controlsName}' where id =${id}`;
  await sequelize
    .query(query)
    .then((item) =>
      this.response({ res, message: "ok", data: controlsCode })
    )
    .catch((error) => console.log(error.message));
} catch (error) {
  console.log(error.message);
}
  • Related