最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 13浏览 0评论

当从节点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时出现错误

我使用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); }) })

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论