【问题标题】:Insert statement with where clause doesnt run on nodejs mysql带有where子句的插入语句不在nodejs mysql上运行
【发布时间】:2016-03-09 08:34:33
【问题描述】:

代码:

function setvalue(val) {

        idoutput=val;
        base62val=Base.encode(idoutput);
        var baseinsert = {ShortUrlCode:base62val};
        console.log(idoutput);
        console.log(base62val);
        con.query('INSERT INTO URLTABLE set ?  where ID = ?',[baseinsert,idoutput],function(err){
        if(err) console.log(err);
        })
        console.log("short inserted");
        con.end();
}

我收到的错误:

{ [Error: ER_PARSE_ERROR: 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 'where ID = 38' at line 1]
  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlState: '42000',
  index: 0 }

【问题讨论】:

  • ... set column_name=? where...
  • 这和 AWS 有什么关系?

标签: javascript mysql node.js amazon-web-services npm


【解决方案1】:
'INSERT INTO URLTABLE set ?  where ID = ?'

您忘记提及要“设置”的列名。

 'INSERT INTO URLTABLE SET column_name = ? (, column_name2 = ?,...) WHERE ID = ?'

是正确的语法

编辑:

请注意,“标准化”您的 SQL 查询总是更好,在这种情况下,您最好使用下面的标准 SQL 语法进行 INSERT(而不是使用您的特定 MySQL 语法):

INSERT INTO URLTABLE (a, b, c) VALUES (?,?,?)

【讨论】:

  • @RevanthPenugonda 欢迎您。将答案标记为已接受。每次您提出关于 SO 的问题并得到等待的答案时,不要忘记将好的答案标记为已接受
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多