tracker issue : CF-3821118

select a category, or use search below
(searches all categories and all time range)
Title:

MySQL 5.6 datetime rounding error

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/NotABug

Reporter/Name(from Bugbase): Rafael Salomon / Rafael Salomon (Rafael Salomon)

Created: 09/09/2014

Components: Database

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final /

Priority/Frequency: Major / All users will encounter

Locale/System: English / Win 2008 Server R2 64 bit

Vote Count: 0

Problem Description: using datetime(0) fields in MySQL 5.6 will produce rounding errors

Steps to Reproduce:

Create test table in MySQL 5.6.4 or higher:
CREATE TABLE `test` (
 `id` int(11) NOT NULL,
 `ts` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Create timestamp:
<cfset ts = ParseDateTime("2014-09-09 08:47:34.997")>

Insert timestamp into test table:
<cfquery>
INSERT INTO test
(
	id,
	ts
)
VALUES
(
	1,
	<cfqueryparam value="#ts#" cfsqltype="cf_sql_timestamp">
)
</cfquery>

retrieve timestamp:
<cfquery name="test" datasource="#application.logdatasource#">
SELECT ts
FROM test
WHERE id = 1
</cfquery>

compare cf timestamp to database ts:
<cfoutput>#(ts EQ test.ts)#</cfoutput>


Actual Result:
NO

Expected Result:
YES

Any Workarounds:
You can change the database field to datetime(3) or you can use DateFormat() and TimeFormat() to generate a timestamp string without milliseconds and insert that into the database.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3821118

External Customer Info:
External Company:  
External Customer Name: Rafael Salomon
External Customer Email:  
External Test Config: My Hardware and Environment details:

Windows 2008 Server R2 64 bit

Attachments:

Comments:

The workaround specified is actually the right thing to do. The default precision in MySQL for the datetime fraction is 0. datetime(3) has to be given to maintain the 3 digit fraction being given in this case.
Comment by Himavanth R.
10958 | November 18, 2014 11:33:17 PM GMT
It's not a matter of maintaining the 3 digit fraction. The problem is that ColdFusion doesn't round correctly. It should be able to compare dates with different levels of precision correctly.
Comment by External U.
10959 | November 19, 2014 06:56:34 AM GMT
Agreed partially. The testcase checks for equality between 2014-09-09 08:47:34.997 and 2014-09-09 08:47:34 which should return false and is working as expected. But greater or lesser comparisons should work. Is that what you are referring to?
Comment by Himavanth R.
10960 | November 24, 2014 11:34:41 PM GMT