Opened 15 years ago
Last modified 15 years ago
#642 assigned defect
Sqlite filtering on number with more that 5 decimal fails
Reported by: | bscott | Owned by: | traianstanev |
---|---|---|---|
Priority: | major | Milestone: | 3.5.0 |
Component: | SQLite Provider | Version: | 3.5.0 |
Severity: | 3 | Keywords: | |
Cc: | External ID: |
Description
I in a numeric field we have some values with more that 5 decimals the filter won't work
example update table set column = 1.00001 select * from table where column = 1.00001 This works fine
but update table set column = 1.000001 select * from table where column = 1.000001 does not return any records
Bruno
Attachments (1)
Change History (12)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
I have created the table using FDOdatatype_double In SqlLiteStudio it tell me it's REAL
comment:3 by , 15 years ago
In general, you are not supposed to compare floating point numbers directly. 1.000001 is an infinite fraction in binary, which means that it could get rounded or truncated, depending on how the code was compiled. My guess is that the binary representation stored in the database differs by one bit from the number you use to compare due to different string to double conversion code being used resulting in rounding/truncation discrepancy.
comment:4 by , 15 years ago
The same query works find when executed out of FDO. If i run "select * from table where column = 1.000001" in a native SQLIte engine it works fine.
By the way > , < , >= , <= have the same bug.
Really likely that the String/Double truncation is in the provider
comment:5 by , 15 years ago
Was the native SQLite engine compiled with /fp:fast and SSE2 settings turned on?
comment:6 by , 15 years ago
i can't tell i've tested against
Sqllite Studio SqlLite Database Browser 2 SqlLiteMan
All 3 works fine
comment:8 by , 15 years ago
Actually we are ruuning our unittest in 32 bit We will run then in 64 bit as soon as we will validate the 32 bit platform
comment:9 by , 15 years ago
I'm asking because floating point is different on the two, on 64 bit, all operations on double are always done to 64 bit, while on 32 bit, the floating point unit has 80 bit precision which doesn't always get truncated to 64 bits before comparisons are performed, depending on the compiler optimization settings used. So those operations can give different results on 32 vs 64.
by , 15 years ago
Attachment: | Sqlite_filterOnDouble.patch added |
---|
comment:10 by , 15 years ago
I found the problem, I've taken the same double precision approach as the GenericRdbms and the KingOracle provider Patch is attached
comment:11 by , 15 years ago
Status: | new → assigned |
---|
Indeed, you're right, snprintf would screw it up before it even got to the floating point comparison instructions.
What do you mean by numeric -- REAL?