-
-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change the way types for prepared statement parameters are calculated #1407
base: master
Are you sure you want to change the base?
Conversation
…n inferring from input variables
ref #1239 |
@vlasky when you have time can you try this brach to see if it fixes It's a potentially backwards incompatible change in some scenarios, I'm thinking to release it as a major version bump. Maybe alpha release initially |
Hello @sidorares |
Any updates on this? |
@mlucic unfortunately no progress here (but its quite high in my priority) The way I want to implement this currently is different from this PR though. The plan is:
const mediumintparam = mysql.TypedParameter.MEDIUMINT(123);
const floatparam = mysql.TypedParameter.FLOAT(123);
conn.execute('select ?+? as sum', [mediumintparam, floatparam]); when used via type helper the type sent with COM_EXECUTE is always what you specify
step 1) can be done now and would help solving current edge cases with a bit of manually added typings ( as in mysql types metadata in users code, not typescript ) after that we can add step 2 to make default map work with no surprises most of the time. Mysql is quite capable of casting back to a correct value on a server side, in earlier versions of this driver all example table:
I'm starting to think simple "always send (parameter.toString()) as VAR_STRING" unless the type is explicitly specified by user" might be actually the best behaviour |
Currently types are inferred based on what is in the input (Date -> mysql date, js number -> mysql double, everything else - string ). This used to work ok until mysql server version 8.0.22
Calling
execute('SELECT * from foo limit ?' , [1])
results inIncorrect arguments to mysqld_stmt_execute
error. The type of the parameter server expects ( LONGINT ) is incompatible to what is actually sent ( DOUBLE ).The fix is to use parameters column definitions returned from the previous
prepare()
call and use types from there instead of inferring type from the provided input