Closed skylarmt closed 5 years ago
Possibly related to #694 and #797
You may consider using BETWEEN operator [><]
and [<>]
for this case. https://medoo.in/api/where
There are two latitude
and longitude
condition in the same array. That's will be conflict.
$where = ["AND" => [
"latitude[><]" => [50.98, 50.99],
"longitude[><]" => [25.11, 25.99]
]];
The thing is, it works fine if searching for 21
in the range 20 - 22
, but breaks with 20.5
if searching with 20.1 - 20.9
, because 20.1
becomes 20
and 20.9
becomes 20
(or so it seems).
Your [><]
solution works, but what I did should work, and I know it did work as of at least version 1.1.3, thanks to some old code I dug up that did the exact same thing. That makes it a regression, and dangerous because it changes the expected results. The SQL code from $database->debug()
works as expected too, so it's not good. My guess is that numbers are either being rounded down or cast to int somewhere.
@skylarmt Yes, I will fix for this.
Just FYI, I can confirm the [><]
and [<>]
operators are also affected. I thought it was working until I tested my app with different values, at which point Medoo started disagreeing with the expected database results.
Describe the bug It appears that Medoo rounds decimals/floats to integers before comparing. This means that when searching for a record such as
5.5
using["col[<]" => 5.6]
, Medoo will actually return values less than5
. When manually running the SQL query generated by$database->debug()
, the expected result is returned.Information
Sample Code
Output
Expected output
The same data should be returned both times.