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('mit');
console.log(rows);
});
Error:
{ [Error: Column count doesn't match value count at row 1] code: 1136 }
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('mit');
console.log(rows);
});
Error:
{ [Error: Column count doesn't match value count at row 1] code: 1136 }
Share
Improve this question
asked Jun 9, 2016 at 7:54
Akash Sourav NayakAkash Sourav Nayak
2031 gold badge9 silver badges21 bronze badges
10
- I am not sure but just suggestion try with one value maybe the [] format is causing issue. – Neha 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? – Akash Sourav Nayak 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. – Neha Commented Jun 9, 2016 at 8:07
- Then how will you send multiple values Like multiple id,multiple username at a time . – Akash Sourav Nayak 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] – Neha Commented Jun 9, 2016 at 9:41
2 Answers
Reset to default 9In 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.mit();
} catch (err) {
connection.rollback();
//handle error
}
});
https://github./MariaDB/mariadb-connector-nodejs/blob/master/documentation/batch.md
These days, As I know it, mariaDB module was not support bulk insert on the node.js.
https://mariadb./kb/en/library/connectornodejs-pipelining/