使用where子句的Insert语句无法在Node.js mysql上运行 [英] Insert statement with where clause doesnt run on nodejs mysql

查看:211
本文介绍了使用where子句的Insert语句无法在Node.js mysql上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

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 }

推荐答案

'INSERT INTO URLTABLE set ?  where ID = ?'

您忘记提及要设置"的列名.

You forgot to mention column names that you want to "SET".

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

是正确的语法

请注意,始终最好标准化" SQL查询,在这种情况下,最好将以下标准SQL语法用于INSERT(而不是使用特定的MySQL语法):

Note that it is always better to "standardize" your SQL queries, in which case you better use the standard SQL syntax below for an INSERT (instead of using your specific MySQL syntax):

插入URLTABLE(a,b,c)值(?,?,?)

这篇关于使用where子句的Insert语句无法在Node.js mysql上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆