Node.js 用 Mysql 中的数组更新表 [英] Node.js Update Table with Array in Mysql

查看:46
本文介绍了Node.js 用 Mysql 中的数组更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这张桌子.

我的数据在下面,把这张表放在上面.

My datas are below to put this table above.

buffer= [{deviceId: 000002, input2:false, input3:false, input4:false, input5:false, input6:false, input7:false, input8:false, output1:false, output2:false, output3:false, output4:false, output5:false, output6:false, output7:false, output8:false},
{deviceId: 000001, input2:false, input3:false, input4:false, input5:false, input6:false, input7:false, input8:false, output1:false, output2:false, output3:false, output4:false, output5:false, output6:false, output7:false, output8:false}]

我想把我的数据放在这个查询中

I'm tring to put my data with this query

dbConnect.query("update datas set input1=?, input2=?, input3=?, input4=?, input5=?, input6=?, input7=?, input8=?, output1=?, output2=?, output3=?, output4=?, output5=?, output6=?, output7=?, output8=? where deviceId=?", [buffer],
function (err, rows, fields) {
     if (!err) {
        console.log("OK")
       } else {
        console.log("ERROR")
    }
})

下面还有错误

sqlMessage: "你的 SQL 语法有错误;检查手册对应于您的 MySQL 服务器版本的正确语法在000002"附近使用,input2=?, input3=?, input4=?, input5=?, input6=?,input7=?, input8=?, ' at line 1', sqlState: '42000', index: 0,
sql: "更新数据集 input1='[object Object]', '000002', input2=?,input3=?, input4=?, input5=?, input6=?, input7=?, input8=?, output1=?,output2=?, output3=?, output4=?, output5=?, output6=?, output7=?,输出8=?其中 deviceId=?"

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 ''000002', input2=?, input3=?, input4=?, input5=?, input6=?, input7=?, input8=?, ' at line 1", sqlState: '42000', index: 0,
sql: "update datas set input1='[object Object]', '000002', input2=?, input3=?, input4=?, input5=?, input6=?, input7=?, input8=?, output1=?, output2=?, output3=?, output4=?, output5=?, output6=?, output7=?, output8=? where deviceId=?"

我需要你的帮助,谢谢.

I need your help, Thanks.

推荐答案

我找到了问题的解决方案.需要使用

I found solution of my problem. need to use

insert into TABLENAME(key, column1, column2, ...) values (?),(?),... on duplicate key update column1=value(column1), column2=value(column2), ...;

但是有一个细节,就是key列必须是unique index

but there is one detail, that is key column have to be unique index

这篇关于Node.js 用 Mysql 中的数组更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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