【发布时间】:2019-06-29 08:30:12
【问题描述】:
我在更新表格中的多行时遇到问题。
以下是我的数据
const update_Data = upins_data.map(
upins_data => [{
upin_id: upins_data.upin_id,
media_type: upins_data.media_type,
land: upins_data.land
}]
);
它有多个值。
我已经厌倦了以下代码
var updateSecTab = `UPDATE tb_bid_upins SET upin_id=?,media_type=?,land=? WHERE bid_id = ?`;
var query = db.query(updateSecTab,[update_Data,cond],function(error,result,fields){
if (error) { /**If error while inserting into table 2 it rowback the Transaction */
console.log('in err 1');
return db.rollback(function () {
throw err;
});
}
db.commit(function (err, result3) {
if (err) {
console.log('in err 2');
return db.rollback(function () {
throw err;
});
}
/**Send success result to front end */
console.log('success!');
res.send(JSON.stringify(result));
})
});
console.log(query.sql);
当我打印查询时,它给出的结果如下
UPDATE tb_bid_upins SET upin_id=('[object Object]'), ('[object Object]'),media_type=1,land=? WHERE bid_id = ?
【问题讨论】:
-
你能显示
update_Data和cond对象吗? -
@Molda 这是我的更新数据对象
[ [ { upin_id: 1, media_type: 5, land: 'Rakhiyal Circle' } ], [ { upin_id: 3, media_type: 6, land: 'Rakhiyal Circle' } ] ]这是条件 bid_id=1 -
我认为您不能以这种方式进行多次更新。看到这个答案stackoverflow.com/a/29519758/3284355
-
@Molda 我已经看到了这个答案。这样对吗??
-
我不知道。你也可以试试这个stackoverflow.com/a/34866431/3284355,这可能会更好,因为它只是单个查询。