You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importmysqlfrom'mysql2/promise';constconnection=awaitmysql.createConnection({host: 'myhost',user: 'mydbuser',password: 'mydbpass',database: 'mydb',namedPlaceholders: true});(async()=>{constsql="SELECT `code` "+"FROM `tag` "+"WHERE `author` = :USER AND `count` = :COUNT "+"LIMIT :LIMIT";constdata={USER: "myuser",// Ok COUNT: 10,// OkLIMIT: 3// With number type not works it, but with string type "3" works it.};try{const[results]=awaitconnection.execute(sql,data);console.log(results);}catch(err){console.log(err);}})();
The error
Error: Incorrect arguments to mysqld_stmt_execute
at PromiseConnection.execute (..AbortController../src/node_modules/mysql2/promise.js:112:22)
at file://.../src/test.js:31:44
at file://.../src/test.js:36:3
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ER_WRONG_ARGUMENTS',
errno: 1210,
sql: 'SELECT `code` FROM `tag` WHERE `author` = ? and `count` = ? LIMIT ?',
sqlState: 'HY000',
sqlMessage: 'Incorrect arguments to mysqld_stmt_execute'
Environment
mysql2: 3.10.1
node: v20.13.1
Question
Is there a way to avoid the error and use the number type in LIMIT clause without having to convert it to a string type?
The text was updated successfully, but these errors were encountered:
alditis
changed the title
namedPlaceholders: "ER_WRONG_ARGUMENTS" in data object with property number type.
namedPlaceholders: "ER_WRONG_ARGUMENTS" in data object with property number type for LIMIT clause.
Jun 21, 2024
Description
I have noticed some behavior that I did not expect in the LIMIT clause.
When I run the query with data.LIMIT = 3 (number type) not works it.
But with data.LIMIT = "3" (string type) works it.
Reproducing error
The error
Environment
mysql2: 3.10.1
node: v20.13.1
Question
Is there a way to avoid the error and use the number type in LIMIT clause without having to convert it to a string type?
The text was updated successfully, but these errors were encountered: