节点mysql批量插入转换后的查询错误

时间:2018-07-19 07:13:47

标签: mysql node.js node-mysql

我正在尝试使用Node(mysqljs)进行批量mysql查询。由于某种原因,查询似乎未正确转换。

const mysqlConnection = mysqlPool((err, connection) => {
   let sql2 = `insert into core_acc_transaction_ledger_detail (ID_TRANSACTION_LEDGER_HEADER,ID_LEDGER_ACCOUNT,CR,DR,LOCATION_ID,STATUS,IS_ACTIVE,REMARK) values (?)`;
   console.log('Running query : ' + sql2);
   var arr = [['35', '21', '500.00', '500.00', '', '', '1', ''], ['35', '23', '500.00', '500.00', '', '', '1', '']];
   var query = connection.query(sql2,[arr], (err, rows) => {
       console.log('sql2 :: ' + query.sql);
       if (err) {
           console.log('db query error : ' + err.message);
       }
       else{
           console.log('transactionLedgerDetails added : ' + rows.insertId);    
           connection.release();;

       }
   });
});

我可以看到以下输出:

Running query : insert into core_acc_transaction_ledger_detail (ID_TRANSACTION_LEDGER_HEADER,ID_LEDGER_ACCOUNT,CR,DR,LOCATION_ID,STATUS,IS_ACTIVE,REMARK) values (?)
sql2 :: insert into core_acc_transaction_ledger_detail (ID_TRANSACTION_LEDGER_HEADER,ID_LEDGER_ACCOUNT,CR,DR,LOCATION_ID,STATUS,IS_ACTIVE,REMARK) values ((35, 21, 500, 500, '', '', 1, ''), (35, 23, 500, 500, '', '', 1, ''))
db query error : ER_OPERAND_COLUMNS: Operand should contain 1 column(s

转换已在值列表周围添加了多余的括号。

0 个答案:

没有答案