skip to Main Content

Hi All I have a node program where I am trying to insert a byte array to database . My code goes like this

const query = 'INSERT INTO spreaddata.workbook  (user_email,workbook_data) VALUES(?,?) ';
sql.query(query, [jsonData.userEmail, jsonData.workbook_data]);

Where jsonData.workbook_data is byte array
But I am getting below error when I execute the query

 code: 'ER_WRONG_VALUE_COUNT_ON_ROW',

  errno: 1136,

  sqlState: '21S01',

  sqlMessage: "Column count doesn't match value count at row 1",

  sql: "INSERT INTO spreaddata.workbook  (user_email,workbook_data) VALUES('[email protected]',80, 75, 3, 4)

For some reason instead of including passed array as [80,75,3,4] it is placing extracted data 80,75,3,4 in the query

What is the problem here

2

Answers


  1. You are passing more data that columns exist.

    (user_email,workbook_data) VALUES <------ Here are two columns of definition
    ('[email protected]',80, 75, 3, 4) <------ Here are four columns of data
    
    Login or Signup to reply.
  2. const values = [jsonData.workbook_data]; // <-- fix
    
    const query = 'INSERT INTO spreaddata.workbook  (user_email,workbook_data) VALUES(?,?) ';
    sql.query(query, [jsonData.userEmail, values]); <-- fix 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search