当从节点js更新SQL时出现错误

编程入门 行业动态 更新时间:2024-10-11 15:15:19

当从<a href=https://www.elefans.com/category/jswz/34/1771452.html style=节点js更新SQL时出现错误"/>

当从节点js更新SQL时出现错误

我使用for循环更新sql命令。

喜欢这样

for(var i=count1; i < count2;i++){        
  Book.TimeStart = Times[I]
  console.log(Book.TimeStart)
  sql = sql + `UPDATE projectroom.Details SET BookingId = `+Book.BookingId+`, status = 'W' 
  WHERE RoomID = `+Book.RoomID+` 
  and dates = '`+Book.Dates+`'
  and TimeId = (Select TimeId from projectroom.Timeslot where TimeStart = '`+Book.TimeStart+`'); \n`
}

如果来自JSON的数据仅进入循环一次。这不是错误。

但是它在循环中不止一个。这是错误的。 (我使用mySQL配置)

这是我的错误:

code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE projectroom.Details
SET BookingId = 193, status = 'W' WHERE RoomID = 101 ' at line 2",
  sqlState: '42000',
  index: 0,
  sql: "UPDATE projectroom.Details SET BookingId = 193, status = 'W' WHERE RoomID = 101 and dates = '2020-03-16'and TimeId = (Select TimeId from projectroom.Timeslot where TimeStart = '09:00:00'); \n" +
    "UPDATE projectroom.Details SET BookingId = 193, status = 'W' WHERE RoomID = 101 and dates = '2020-03-16'and TimeId = (Select TimeId from projectroom.Timeslot where TimeStart = '09:30:00'); \n" +
    "UPDATE projectroom.Details SET BookingId = 193, status = 'W' WHERE RoomID = 101 and dates = '2020-03-16'and TimeId = (Select TimeId from projectroom.Timeslot where TimeStart = '10:00:00'); \n"
}
回答如下:那对我有用:

router.put('/:id', (req, res)=>{ console.log(req.body) console.log(req.params) console.log(req.session) let sql = `UPDATE expend SET ? WHERE expen_id = ?` let params = [ req.body, req.params.id ]; conexion.query(sql, params, function(err,result,fields){ let respuesta; if (err){ respuesta={ status: 'error', message: 'Error al modificar la receta', err: err } } else{ respuesta= { status: 'ok', message: 'la respuesta se agregó', } } res.json(respuesta); }) })

更多推荐

当从节点js更新SQL时出现错误

本文发布于:2024-05-07 09:56:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755709.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   出现错误   js   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!