Bug #68523 ResultSet::getString does not return fractional seconds from DATETIME(N) columns
Submitted: 28 Feb 2013 13:05 Modified: 2 Feb 2015 16:21
Reporter: Lucas Cipolla Email Updates:
Status: Closed Impact on me:
Category:Connector / C++ Severity:S3 (Non-critical)
Version:1.1.2 OS:Windows (MySQL Server 5.6.10)
Assigned to: Hemant Dangi CPU Architecture:Any
Tags: DATETIME(6), getstring, microseconds, milliseconds, TIMESTAMP(6)

[28 Feb 2013 13:05] Lucas Cipolla
Fractional seconds work as expected in the MySQL client:

mysql> select NOW(6);
| NOW(6)                     |
| 2013-02-28 07:47:11.171875 |
1 row in set (0.00 sec)

However, when performing the same query in C++, ResultSet::getString() returns "2013-02-28 07:47:11" without any fractional seconds.  The same is true when selecting from table columns defined as DATETIME(N).

When using DATE_FORMAT() with %f, though, getString() DOES return the fractional seconds in the string.

I am running Windows 7 64-bit with the 64-bit versions of both MySQL Server 5.6.10 and MySQL Connector/C++ 1.1.2.

How to repeat:
Perform a query on a DATETIME(6) column in C++ and use ResultSet::getString() to retrieve the datetime value.
[20 Jun 2013 12:11] Bogdan Degtyariov
test case

Attachment: bug68523.cpp (text/plain), 787 bytes.

[20 Jun 2013 12:17] Bogdan Degtyariov
Thank you for reporting the problem in MySQL Connector/C++.

It looks that the issue has been fixed in Connector/C++ 1.1.3.
I uploaded the test case, which I used for my verification. It displayed the result correctly with the fractional parts:

time = 2013-06-20 21:57:25.689827

Please let me know whether the version 1.1.3 is showing the correct result for you too.
[21 Jul 2013 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[22 Jul 2013 7:34] Bogdan Degtyariov

do you have any feedback? Please note that the bug will be automatically closed if we do not receive any replies from you.
[23 Jul 2013 11:21] Lucas Cipolla

Sorry it took me a little while to get back to this.  Your test case does indeed work, but after doing some more investigation, it looks like it also worked with version 1.1.2 of the connector.  However, if you change your test case to use a PreparedStatement, it does not appear to work in either 1.1.2 or 1.1.3.  I did not notice this distinction before since the particular piece of code for my project where I found the issue was using a PreparedStatement.

Thanks for your time and help.
[25 Jul 2013 11:54] Bogdan Degtyariov
Lucas, thank you for your clarification.
I was able to repeat the bug using sql::PreparedStatement.

The test case comes in the next post.
[25 Jul 2013 11:56] Bogdan Degtyariov
Test case version 2

Attachment: bug68523.cpp (text/plain), 890 bytes.

[20 Jan 2015 11:05] Hemant Dangi
patch with testcase

Attachment: patch_68523.diff (application/octet-stream, text), 3.78 KiB.

[23 Jan 2015 9:26] Hemant Dangi
Posted by developer:
ResultSet::getString() not returning fractional seconds for prepared statements.
Committed as rev#1022.
[2 Feb 2015 16:21] Paul DuBois
Noted in 1.1.6 changelog.

For prepared statements, getString() did not return the fractional
seconds part from temporal columns that had a fractional sections