Bug #60598 nativeSQL() truncates fractional seconds
Submitted: 23 Mar 2011 8:37 Modified: 25 Oct 2012 22:49
Reporter: Philip Stoev Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:launchpad OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any

[23 Mar 2011 8:37] Philip Stoev
Description:
nativeSQL() function truncates fractional seconds even though MySQL is capable of processing and/or truncating them internally.

How to repeat:
String input = "SELECT {ts '2001-02-03 04:05:06.007' } , {t '11:22:33.444' }";
String output = this.conn.nativeSQL(input);
String expected = "SELECT '2001-02-03 04:05:06.007' , '11:22:33.444'";
assertEquals(expected, output);

instead, output is

SELECT '2001-02-03 04:05:06' , '11:22:33'

Suggested fix:
pass fractional seconds to the server where they will be processed or truncated.
[24 Mar 2011 13:54] Mark Matthews
Work for supporting fractional seconds will not start until WL#946 has passed architectural review and the fractional second units are specified.
[25 Oct 2012 22:49] John Russell
Added to changelog for 5.1.23: 

The nativeSQL() method would truncate fractional seconds rather than
preserving the fractional part in the output string.
[26 Oct 2012 23:31] John Russell
Clarified the changelog entry with version-specific details:

The nativeSQL() method would always truncate fractional seconds
rather than preserving the fractional part in the output string. Now
Connector/J checks the server version: it preserves the fractional
part for MySQL 5.6.4 and greater, and truncates the fractional part
for older versions.