You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2010/06/08 11:18:24 UTC
svn commit: r952581 - in /db/derby/code/trunk/java:
engine/org/apache/derby/iapi/types/SQLDate.java
engine/org/apache/derby/iapi/types/SQLTimestamp.java
testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
Author: kahatlen
Date: Tue Jun 8 09:18:23 2010
New Revision: 952581
URL: http://svn.apache.org/viewvc?rev=952581&view=rev
Log:
DERBY-3856: difference between Embedded vs DerbyNetClient in format of
return from timestamp(cast(? as varchar(32)))
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/trunk/java/engine/org/apache/derby/iapi/types/SQLDate.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDate.java?rev=952581&r1=952580&r2=952581&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDate.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDate.java Tue Jun 8 09:18:23 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/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java?rev=952581&r1=952580&r2=952581&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLTimestamp.java Tue Jun 8 09:18:23 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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java?rev=952581&r1=952580&r2=952581&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java Tue Jun 8 09:18:23 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);
+ }
}