db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r962640 - in /db/derby/code/branches/10.5: ./ 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 Fri, 09 Jul 2010 19:12:50 GMT
Author: mikem
Date: Fri Jul  9 19:12:50 2010
New Revision: 962640

URL: http://svn.apache.org/viewvc?rev=962640&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.5 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.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLDate.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul  9 19:12:50 2010
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.6:957000
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,829410,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,903108,905224,908418,908586,909176,911315,915733,916075,916897,918359,921028,927430,928065,936215,942286,942476,942480,942587,946794,948045,948069,951346,952138,954748,955001,955634,956075,956445,956659,958163,959550
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,829410,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,903108,905224,908418,908586,909176,911315,915733,916075,916897,918359,921028,927430,928065,936215,942286,942476,942480,942587,946794,948045,948069,951346,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLDate.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLDate.java?rev=962640&r1=962639&r2=962640&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLDate.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLDate.java Fri Jul
 9 19:12:50 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.5/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java?rev=962640&r1=962639&r2=962640&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
Fri Jul  9 19:12:50 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.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java?rev=962640&r1=962639&r2=962640&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
Fri Jul  9 19:12:50 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