-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Problem using execute and array parameters #476
Comments
This is the way prepared statements work, I think we should document that better
query vs execute step by step: query:
execute:
Result from prepare step above is cached, with next I agree that this is confusing but this is how prepared statement work. We should improve this with better documentation and maybe some parameter validation warnings/errors like _"hey, are you sure you want to send your {foo: 'bar'} parameter to prepared statement? It'll be sent as [Object object]!'' I'll keep this issue open to track improvements in documentation - feel free to suggest your |
Late to the party as usual, but is the issue essentially that you'd have to prepare new statement every time someone used an array of a different size? |
@BorePlusPlus not exactly. Prepared statements api does not turn array parameters into list unlike non-prepared version. You can work around this by providing as much placeholders as you have elements in the array but this will result in new prepared statement created on the server |
mysql2 query() function will actually prepare the query before it's sent to the DB server. That makes it possible to write queries like: 'select * from users where id in(?)' + [1, 2, 3] More info: sidorares/node-mysql2#476 (comment)
Hi,
mysql2 is a good alternative to mysql, but there is a little bug I guess.
I try to prepare a statement with an array parameter, that should be turned into a list. It works with
query
but not withexecute
.I'm using mysql2 v1.1.2.
The text was updated successfully, but these errors were encountered: