2021年4月8日星期四

Bulk inserting to MYSQL through NodeJS With Multiple Placeholders and SELECT

I'm having trouble getting the following to work. Any help would be massively appreciated

var values = [          ['Product1', 1, 1],          ['Product2', 1, 1],      ];        dbConn.query(          'INSERT INTO tblQuoteItems (ProductIDFK,QuoteIDFK,CustomerIDFK) VALUES ((SELECT ProductIDPK FROM tblProducts WHERE ProductName=?),?,?)',          [values],          function (err, res) {              if (err) {                                    result(null, err);              } else {                                    result(null, res);              }          }      );  

the error response shows that it is dumping all of the array into the first placeholder rather than one value per placeholder and iterating over the number of array elements. Here is the SQL created from the above :

INSERT INTO tblQuoteItems (ProductIDFK,QuoteIDFK,CustomerIDFK) VALUES ((SELECT ProductIDPK FROM tblProducts WHERE ProductName=('Product1', 1, 1), ('Product2', 1, 1)),?,?)  
https://stackoverflow.com/questions/67013721/bulk-inserting-to-mysql-through-nodejs-with-multiple-placeholders-and-select April 09, 2021 at 09:03AM

没有评论:

发表评论