SQL node.js什么似乎是一个有效的查询语法错误?

我在桌子上运行更新以设置位置。 我解压查询并手动运行在我的数据库上,工作正常,但通过connection.query()传递时,似乎认为我的node.js控制台中有语法错误。

function sendShipPosition(position) { var input = ''; if (position.moving === true) { var currentdate = new Date(); var datetime = currentdate.getFullYear() + "-" + (currentdate.getMonth()+1) + "-" + currentdate.getDate() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds(); var input = ', moving_datetime = ' + datetime; } connection.query('UPDATE ships SET x_axis = :x, y_axis = :y' + input + ' WHERE ship_id = :ship_id'), { x: parseInt(position.x), y: parseInt(position.y), ship_id: 1 }; } 

这里是语法错误:

错误

这里是'position'variables的input数据值:

 { x: '-605', y: '-257', moving: 0 } 

我希望我没有太多的愚蠢,并为低质量的问题感到抱歉。

谢谢

该函数将生成SQL代码,该代码在datetimevariables周围缺less引号,导致无效的SQL代码。

 function sendShipPosition(position) { var input = ''; if (position.moving === true) { var currentdate = new Date(); var datetime = currentdate.getFullYear() + "-" + (currentdate.getMonth()+1) + "-" + currentdate.getDate() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds(); # Here! var input = ', moving_datetime = \'' + datetime + '\'' } connection.query('UPDATE ships SET x_axis = :x, y_axis = :y' + input + ' WHERE ship_id = :ship_id'), { x: parseInt(position.x), y: parseInt(position.y), ship_id: 1 }; }