Bug #96382 rs.getDouble() gives different results for float fields when useCursorFetch=true
Submitted: 31 Jul 2019 9:13 Modified: 31 Jul 2019 10:39
Reporter: Slawomir Chodnicki Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.17 OS:Any
Assigned to: CPU Architecture:Any

[31 Jul 2019 9:13] Slawomir Chodnicki
Description:
Mysql Server: official docker image 8.0.17
Connector/J 8.0.17

With useCursorFetch=true, when retrieving values stored as FLOAT, resultSet.getDouble() returns a value that is far off from the closest Double representing the stored value. 

With useCursorFetch=false, the expected Double is returned from the call.

How to repeat:
CREATE TABLE my_floats (
  id varchar(10),
  x_float float,
  x_double double
);

INSERT INTO my_floats VALUES('pi', 3.141592653589793, 3.141592653589793);

-- The x_float column contains now a value ~3.14159.

Now select the data back:
SELECT * FROM my_floats WHERE id = 'pi';

With useCursorFetch=false you get:

{
  id: 'pi',
  x_float: 3.14159,
  x_double: 3.141592653589793,
}

both values were retrieved using rs.getDouble()

With useCursorFetch=true you get:

{
  id: 'pi',
  x_float: 3.1415927410125732,
  x_double: 3.141592653589793,
}

both values were retrieved using rs.getDouble()

Suggested fix:
The expected result is that both of these approaches return the first result, where a double value closest to the stored float was returned.
[31 Jul 2019 10:39] Umesh Shastry
Hello Slawomir,

Thank you for the report.

regards,
Umesh