Closed leonk-sportsbet closed 3 years ago
Same error when not using backticks:
const result = await db.query(
'SELECT * FROM roles LIMIT ?,?',
[offset, config.listPerPage]
);
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''5000'' at line 1 | 2021-09-28T07:40:39.209Z 44a7448e-bfaf-49cf-b15e-1ae7ecda9644 INFO [Error] Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''5000'' at line 1
I would hardcode the query, to try figure out the real problem.
const result = await db.query("SELECT * FROM roles LIMIT 0, 5000")
and
const result = await db.query("SELECT * FROM roles LIMIT ?, ?", [0, 5000])
An answer to my own question: Unlike MySQL 8, while working with MySQL 5 you need to make sure numbers aren't converted to strings:
const result = await db.query(
`SELECT *
FROM roles LIMIT ?,?`,
[String(offset), String(config.listPerPage)]
);
This works:
const result = await db.query(
`SELECT *
FROM users LIMIT ?,?`,
[Number(offset), Number(config.listPerPage)]
);
I've decided to use serverless-mysql as my "Threads_connected" count hits the limit of max_connections in a few seconds of running data ingestion.
Everything works fine for mysql2 package (except for the Threads_connected count) but with serverless-mysql package, the following code produces an error -
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0','5000'' at line 2
error:Interestingly enough, this works fine:
My query function lives in a separate file and looks like this:
Any idea why this won't work? Also tried without 'String()'.