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 }
10
  • I am not sure but just suggestion try with one value maybe the [] format is causing issue. Commented Jun 9, 2016 at 8:02
  • One value is working but i want to do with multiple value So can you help me how to do it? Commented Jun 9, 2016 at 8:04
  • just suggestion if its help. as i also not tried, why u keeping [] around the {} object ? any reason. if u remove it and try. Commented Jun 9, 2016 at 8:07
  • Then how will you send multiple values Like multiple id,multiple username at a time . Commented Jun 9, 2016 at 8:58
  • I think something like this - var values = [{1,'a','b'}, {2,'v','h'}]; insert into Hash.asn(userid,username,password) values (?,?,?)',[values] Commented Jun 9, 2016 at 9:41

2 Answers 2

9

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

Sign up to request clarification or add additional context in comments.

1 Comment

this answer is premium
-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/

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.