db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r963150 - in /db/derby/code/branches/10.6: ./ java/engine/org/apache/derby/iapi/types/SQLDate.java java/engine/org/apache/derby/iapi/types/SQLTimestamp.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
Date Sun, 11 Jul 2010 21:13:29 GMT
Author: mikem
Date: Sun Jul 11 21:13:28 2010
New Revision: 963150

URL: http://svn.apache.org/viewvc?rev=963150&view=rev
Log:
DERBY-3856: difference between Embedded vs DerbyNetClient in format of
return from timestamp(cast(? as varchar(32)))

backporting change #952581 from trunk to 10.6 branch.

Stop caching the original input string in the parse methods of SQLDate
and SQLTimestamp, and instead generate (and cache) a normalized
datetime string on the first call to getString(). 


Modified:
    db/derby/code/branches/10.6/   (props changed)
    db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLDate.java
    db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
    db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java

Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jul 11 21:13:28 2010
@@ -1,2 +1,2 @@
-/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,952138,952237,954344,954421,954544,954748,955001,955634,956075,956234,956445,956569,956659,957260,958163,958618,959550,962716
+/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,952138,952237,952581,954344,954421,954544,954748,955001,955634,956075,956234,956445,956569,956659,957260,958163,958618,959550,962716
 /db/derby/docs/trunk:954344

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLDate.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLDate.java?rev=963150&r1=963149&r2=963150&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLDate.java (original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLDate.java Sun Jul
11 21:13:28 2010
@@ -471,7 +471,6 @@ public final class SQLDate extends DataT
             {
             case ISO_SEPARATOR:
                 encodedDate = SQLTimestamp.parseDateOrTimestamp( parser, false)[0];
-                valueString = parser.getTrimmedString();
                 return;
 
             case IBM_USA_SEPARATOR:
@@ -507,7 +506,6 @@ public final class SQLDate extends DataT
         }
         if( validSyntax)
         {
-            valueString = parser.checkEnd();
             encodedDate = computeEncodedDate( year, month, day);
         }
         else
@@ -541,7 +539,6 @@ public final class SQLDate extends DataT
                     throw StandardException.newException( SQLState.LANG_DATE_SYNTAX_EXCEPTION);
                 }
             }
-            valueString = dateStr;
         }
     } // end of parseDate
 

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java?rev=963150&r1=963149&r2=963150&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
(original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
Sun Jul 11 21:13:28 2010
@@ -519,7 +519,6 @@ public final class SQLTimestamp extends 
             encodedDate = dateTimeNano[0];
             encodedTime = dateTimeNano[1];
             nanos = dateTimeNano[2];
-            valueString = parser.getTrimmedString();
             return;
         }
         catch( StandardException se)
@@ -533,7 +532,6 @@ public final class SQLTimestamp extends 
             int[] dateAndTime = parseLocalTimestamp( timestampStr, localeFinder, cal);
             encodedDate = dateAndTime[0];
             encodedTime = dateAndTime[1];
-            valueString = timestampStr;
             return;
         }
         catch( ParseException pe){}

Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java?rev=963150&r1=963149&r2=963150&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
(original)
+++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
Sun Jul 11 21:13:28 2010
@@ -1604,14 +1604,8 @@ public final class DateTimeTest extends 
         
         rs = pSt.executeQuery();
         JDBC.assertColumnNames(rs, new String[] { "1", "2" });
-        // See DERBY-3856 - there's a diff between Embedded and DerbyNetClient
-        // in how the cast returns the following...
-        if (usingDerbyNetClient())
-            JDBC.assertFullResultSet(rs, new String[][] { { "1970-01-01",
+        JDBC.assertFullResultSet(rs, new String[][] { { "1970-01-01",
             "2003-03-05 17:05:43.111111" } }, true);
-        else
-            JDBC.assertFullResultSet(rs, new String[][] { { "1970-01-01",
-                "2003-03-05-17.05.43.111111" } }, true);
 
         rs = st.executeQuery("values(2, '20030422190200')");
         rs.next();
@@ -1751,4 +1745,55 @@ public final class DateTimeTest extends 
         
         st.close();
     }
+
+    /**
+     * Regression test case for DERBY-3856. The embedded driver sometimes
+     * returned an unnormalized datetime string when getString() was used
+     * to retrieve the result from an invocation of the unary TIMESTAMP or
+     * DATE function.
+     */
+    public void testDerby3856() throws SQLException {
+        // TIMESTAMP called on literal has always a returned normalized value.
+        assertSingleValue(
+                "values timestamp('2003-03-05-17.05.43.111111')",
+                "2003-03-05 17:05:43.111111");
+
+        // This one used to return the original unnormalized input with the
+        // embedded driver.
+        assertSingleValue(
+                "values timestamp(cast('2003-03-05-17.05.43.111111' " +
+                "as varchar(32)))",
+                "2003-03-05 17:05:43.111111");
+
+        // DATE called on literal has always a returned normalized value.
+        assertSingleValue("values date('10/07/2008')", "2008-10-07");
+
+        // This one used to return the original unnormalized input with the
+        // embedded driver.
+        assertSingleValue(
+                "values date(cast('10/07/2008' as varchar(10)))",
+                "2008-10-07");
+
+        // TIME called on literal has always a returned normalized string.
+        assertSingleValue("values time('10.00.00')", "10:00:00");
+
+        // TIME has also always returned a normalized value for the variant
+        // with a CAST.
+        assertSingleValue(
+                "values time(cast('10.00.00' as varchar(10)))",
+                "10:00:00");
+    }
+
+    /**
+     * Execute an SQL statement and check that it returns a single, specific
+     * value.
+     *
+     * @param sql the statement to execute
+     * @param expectedValue the expected value
+     */
+    private void assertSingleValue(String sql, String expectedValue)
+            throws SQLException {
+        JDBC.assertSingleValueResultSet(
+                createStatement().executeQuery(sql), expectedValue);
+    }
 }



Mime
View raw message