Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
JavaScript MySQL Error while inserting bulk prepared statements

I have a problem. I am trying to insert a few hundred object in my database using prepared bulk statements. The table I am trying to insert into is the following: enter image description here

Then I have the following code:

static save() {
    data = [[1, '', '', 0, 0, 0, 0, 0], [2, '', '', 0, 0, 0, 0, 0], [3, '', '', 0, 0, 0, 0, 0], [4, '', '', 0, 0, 0, 0, 0]];
    let sql = "INSERT INTO Candlestick (openTime, market, `interval`, open, high, low, close, volume) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
    return db.execute(sql, [data]);
}

But this results in the following output:

Error: Incorrect arguments to mysqld_stmt_execute
    at PromisePool.execute (C:\Users\Alexander\Projects\API\node_modules\mysql2\promise.js:359:22)
    at Function.save (C:\Users\Alexander\Projects\API\src\api\v1\models\Candlestick.js:18:19)
    at C:\Users\Alexander\Projects\API\src\api\v1\controllers\candlestickController.js:28:29
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ER_WRONG_ARGUMENTS',
  errno: 1210,
  sql: 'INSERT INTO Candlestick (openTime, market, `interval`, open, high, low, close, volume) VALUES (?, ?, ?, ?, ?, ?, ?, ?);',

When I copy the query and manually set the variables to:

INSERT INTO Candlestick (openTime, market, `interval`, open, high, low, close, volume) VALUES (1, '', '', 0, 0, 0, 0, 0);

The query does get executed in phpmyadmin: enter image description here

Can someone tell me what I am missing...

I am using:
mysql2 - ^2.3.3
mariadb - 10.3.34

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To fix this issue, I had to change the query from:

let sql = "INSERT INTO Candlestick (openTime, market, `interval`, open, high, low, close, volume) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";

to:

let sql = "INSERT INTO Candlestick (openTime, market, `interval`, open, high, low, close, volume) VALUES ?;";

Because every entry in the [data] represent: (1, '', '', 0, 0, 0, 0, 0) So that fill be filled in every time. Also I changed the db.execute to db.query, so the queries will be prepared at the client side. The advantage of that is that you can see the prepared query result in the console, when the query goes wrong.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!