Closed stemis closed 6 years ago
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.
@stemis do you have PDO::ATTR_EMULATE_PREPARES = true ?
I noticed that this option causes this behaviour. Please check #23850
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 usePDO::PARAM_STRING
https://wiki.php.net/rfc/pdo_float_typeThe line that causes the issue is: https://github.com/laravel/framework/blob/59a045343e0994b45b66fd6afa9199c2d566e0ba/src/Illuminate/Database/MySqlConnection.php#L80
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.