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

SQL node.js Syntax error on what seems to be a valid query?

我正在 运行更新 table 以设置位置。我已经提取了查询并在我的数据库中手动 运行 它并且工作正常但是当通过 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'变量的输入数据值:

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

我希望我不是太笨了,很抱歉提出了低质量的问题。

谢谢

此函数将生成 SQL 代码,该代码缺少 datetime 变量周围的引号,从而导致无效的 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
    };
}