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
{{ message }}
Repository navigation
namedPlaceholders: "ER_WRONG_ARGUMENTS" in data object with property number type for LIMIT clause. #2793
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?
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.[/+]on Jun 21, 2024
Activity
[-]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.[/+]SteveRedding commentedon Jul 28, 2024
#1239 in prepare statement mysql2 may convert javascript number type into
mysql double type.
sidorares commentedon Jul 28, 2024
not at the moment, but hopefully soon should be possible with api similar to #1239 (comment)
I'll close this issue for now, feel free to ask questions here @alditis but the progress of the root cause is tracked by #1239