由于这个额外的括号,我得到以下错误
code: 'ER_OPERAND_COLUMNS',
errno: 1241,
sqlMessage: 'Operand should contain 1 column(s)',
sqlState: '21000',
index: 0,
sql: 'INSERT INTO orderedproducts (order_id, product_id, quantity) VALUES ((41, 1, 2), (41, 1, 3), (41, 1, 3))'
}
我使用以下代码生成这个查询
let lastId = results.insertId
let orderedProductSql = 'INSERT INTO orderedproducts (order_id, product_id, quantity) VALUES (?)'
var testData = [
{
productId: 1,
quantity: 2
},
{
productId: 1,
quantity: 3
},
{
productId: 1,
quantity: 3
},
]
let values = testData.reduce((o, a) => {
let ini = []
ini.push(lastId)
ini.push(a.productId)
ini.push(a.quantity)
o.push(ini)
return o
},[])
connection.query(orderedProductSql, [values], (err, results) => {
if (err) {
return connection.rollback(_ => {
throw err
})
}
我如何才能删除这些额外的括号或有任何其他方法,我可以使这项工作?
暂无答案!
目前还没有任何答案,快来回答吧!