2

Whenever i am trying to run my code this is showing the column count doesn't match error.

values=[
    [{id:12227722345,name:"dgssssdavgsgfv",pass:"cvhsssssadfvugod"}],
    [{id:12,name:"ddd",pass:"cvh"}]
   ];

c.query('insert into Hash.asn(userid,username,password) values (?,?,?)',[values],function(err,rows)
{
  if (err)
    console.log(err);

  c.query('commit');
  console.log(rows);

}); 

Error:

{ [Error: Column count doesn't match value count at row 1] code: 1136 }
Akash Sourav Nayak
  • 203
  • 1
  • 8
  • 21

2 Answers2

8

In case anyone is still wondering this you can use connection.batch() to perform bulk queries.

connection.beginTransaction();
connection.query("INSERT INTO BASKET(customerId) values (?)", [1], (err, res) => {
   //must handle error if any
   const basketId = res.insertId;
   try {
     connection.batch("INSERT INTO basket_item(basketId, itemId) VALUES (?, ?)",[
         [basketId, 100],
         [basketId, 101],
         [basketId, 103],
         [basketId, 104],
         [basketId, 105]
     ]);
     //must handle error if any
     connection.commit();
     } catch (err) {
     connection.rollback();
     //handle error
     }
});

https://github.com/MariaDB/mariadb-connector-nodejs/blob/master/documentation/batch.md

kangas08
  • 99
  • 1
  • 9
-1

These days, As I know it, mariaDB module was not support bulk insert on the node.js.

https://mariadb.com/kb/en/library/connectornodejs-pipelining/

  • Welcome to StackOverflow! While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Tân Nov 08 '18 at 03:42