简体   繁体   English

Node.js 用 Mysql 中的数组更新表

[英]Node.js Update Table with Array in Mysql

I have this table.我有这张桌子。

在此处输入图像描述

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")
    }
})

Also error is below下面还有错误

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, sqlMessage:“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以获取在 ''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=?" sql:“更新数据集 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), ...;

but there is one detail, that is key column have to be unique index但是有一个细节,那就是key列必须是unique index

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM