-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Float incorrectly casted to PDO::PARAM_INT in MySQL, should be: PDO::PARAM_STRING #25818
Comments
See also #23850. |
@staudenmeir Thanks for referencing that. I have a read a couple of more issue topics but am still uncertain about why it is not cast to string. The one that really matters is: #16063 , which highlights the issues with JSON comparison However, I think it is safe to say that we should not solve one issue by introducing another. This should at least be mentioned on the Database/Eloquent documentation page that when using a float in the where query, it should first be casted to string. This should already prevent a lot of people having headaches! |
I just tested this on the latest MariaDB 10.3.9 (in Homestead) and it works for me. |
Thanks - I'll close this. @stemis - feel free to submit a PR to the docs with your idea above. |
Laravel will miss-behave in multiple ways with MySQL and PgSQL as documented in various issues and even PRs, because people try to get a fix in but _the_ recommendation right now is to *not* use it. I figured it might save everyones time if ppl fill this out upfront because it's often takes some forth and back until users mention this. See: - laravel#29023 - laravel#23850 - laravel#25818 - laravel#27951 - laravel#28149
Description:
When issuing the following command:
User::where('rating', '>', 2.5)->get()
The query that actually goes to the database is:
WHERE rating > 2
What should go to the database in order for correct behavior:
WHERE rating > '2.5'
This is caused by the MysqlConnection using
PDO::PARAM_INT
According to this wiki article by PHP it should use
PDO::PARAM_STRING
https://wiki.php.net/rfc/pdo_float_type
The line that causes the issue is:
framework/src/Illuminate/Database/MySqlConnection.php
Line 80 in 59a0453
It should be edited to:
@themsaid this is something you have touched before.
If this is intentional, could you maybe explain why floating point values are not converted to strings, as per the wiki article.
The text was updated successfully, but these errors were encountered: