From 6b60fc1dd34bf8fe3c4039bb34e5fb1c52554154 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 18 Sep 2013 13:39:52 +0200 Subject: [PATCH] [#2753] DATE_DIFF() with CURRENT_DATE() returns wrong precision in Oracle --- .../org/jooq/test/_/testcases/DataTypeTests.java | 15 ++++++++++++++- jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java | 15 ++++++++++----- jOOQ/src/main/java/org/jooq/impl/CurrentDate.java | 4 ++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/jOOQ-test/src/org/jooq/test/_/testcases/DataTypeTests.java b/jOOQ-test/src/org/jooq/test/_/testcases/DataTypeTests.java index 07a81a0f1b..2b0977df1d 100644 --- a/jOOQ-test/src/org/jooq/test/_/testcases/DataTypeTests.java +++ b/jOOQ-test/src/org/jooq/test/_/testcases/DataTypeTests.java @@ -60,6 +60,7 @@ import static org.jooq.SQLDialect.SYBASE; import static org.jooq.conf.StatementType.STATIC_STATEMENT; import static org.jooq.impl.DSL.cast; import static org.jooq.impl.DSL.castNull; +import static org.jooq.impl.DSL.currentDate; import static org.jooq.impl.DSL.dateAdd; import static org.jooq.impl.DSL.dateDiff; import static org.jooq.impl.DSL.field; @@ -1582,12 +1583,24 @@ extends BaseTest ts = currentDate().cast(Timestamp.class).as("ts"); + Field d = currentDate().as("d"); + + Record2 record = + create().select(d, ts) + .fetchOne(); + + assertEquals(record.value1().getTime(), record.value2().getTime()); + } @Test public void testUUIDDataType() throws Exception { diff --git a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java index cc49e8896a..7e31019ed5 100644 --- a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java +++ b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java @@ -1650,11 +1650,16 @@ public abstract class jOOQAbstractTest< public void testDateTime() throws Exception { new DataTypeTests(this).testDateTime(); } - - @Test - public void testDateTimeArithmetic() throws Exception { - new DataTypeTests(this).testDateTimeArithmetic(); - } + + @Test + public void testDateTimeArithmetic() throws Exception { + new DataTypeTests(this).testDateTimeArithmetic(); + } + + @Test + public void testCurrentDate() throws Exception { + new DataTypeTests(this).testCurrentDate(); + } @Test public void testManager() throws Exception { diff --git a/jOOQ/src/main/java/org/jooq/impl/CurrentDate.java b/jOOQ/src/main/java/org/jooq/impl/CurrentDate.java index e8a9899225..e70709ddda 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CurrentDate.java +++ b/jOOQ/src/main/java/org/jooq/impl/CurrentDate.java @@ -66,8 +66,8 @@ class CurrentDate extends AbstractFunction { final Field getFunction0(Configuration configuration) { switch (configuration.dialect().family()) { /* [pro] */ - case ORACLE: - return field("sysdate", SQLDataType.DATE); + case ORACLE: + return field("{trunc}({sysdate})", SQLDataType.DATE); case DB2: case INGRES: