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/09/21 18:06:40 UTC
svn commit: r999479 - in /db/derby/code/trunk/java:
engine/org/apache/derby/iapi/types/SQLChar.java
engine/org/apache/derby/iapi/types/SQLTimestamp.java
testing/org/apache/derbyTesting/functionTests/tests/lang/DateTimeTest.java
Author: kahatlen
Date: Tue Sep 21 16:06:40 2010
New Revision: 999479
URL: http://svn.apache.org/viewvc?rev=999479&view=rev
Log:
DERBY-4625: TIMESTAMP function doesn't accept nanoseconds
Patch contributed by C.S. Nirmal J. Fernando <ni...@gmail.com>.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.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/SQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java?rev=999479&r1=999478&r2=999479&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java Tue Sep 21 16:06:40 2010
@@ -1565,19 +1565,17 @@ readingLoop:
formatJDBCTime( cal, sb);
sb.append('.');
- int micros =
- (theValue.getNanos() + SQLTimestamp.FRACTION_TO_NANO/2) /
- SQLTimestamp.FRACTION_TO_NANO;
+ int nanos = theValue.getNanos();
- if (micros == 0)
+ if (nanos == 0)
{
// Add a single zero after the decimal point to match
// the format from Timestamp.toString().
sb.append('0');
}
- else if (micros > 0)
+ else if (nanos > 0)
{
- String microsStr = Integer.toString( micros);
+ String microsStr = Integer.toString( nanos);
if(microsStr.length() > SQLTimestamp.MAX_FRACTION_DIGITS)
{
sb.append(
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=999479&r1=999478&r2=999479&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 Sep 21 16:06:40 2010
@@ -85,8 +85,8 @@ public final class SQLTimestamp extends
implements DateTimeDataValue
{
- static final int MAX_FRACTION_DIGITS = 6; // Only microsecond resolution on conversion to/from strings
- static final int FRACTION_TO_NANO = 1000; // 10**(9 - MAX_FRACTION_DIGITS)
+ static final int MAX_FRACTION_DIGITS = 9; // Only nanosecond resolution on conversion to/from strings
+ static final int FRACTION_TO_NANO = 1; // 10**(9 - MAX_FRACTION_DIGITS)
static final int ONE_BILLION = 1000000000;
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=999479&r1=999478&r2=999479&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 Sep 21 16:06:40 2010
@@ -1236,16 +1236,16 @@ public final class DateTimeTest extends
}
/**
- * Don't allow more than microseconds in ISO format: cloudscape rejects.
+ * Don't allow more than nanoseconds in ISO format.
*/
- public void testISOFormat_MoreThanMicroseconds() throws SQLException{
+ public void testISOFormat_MoreThanNanoseconds() throws SQLException{
Statement st = createStatement();
assertStatementError("22007", st, "insert into ts (ts1) values "
- + "('2003-03-05-17.05.43.999999999')");
+ + "('2003-03-05-17.05.43.999999999999')");
assertStatementError("22007", st, " insert into ts (ts1) values "
- + "('2003-03-05-17.05.43.999999000')");
+ + "('2003-03-05-17.05.43.999999999000')");
st.close();
}
@@ -1785,6 +1785,15 @@ public final class DateTimeTest extends
}
/**
+ * Test case to show that timestamp function accepts nanoseconds
+ * resolution (DERBY-4625).
+ */
+ public void testNanosecondResolution() throws SQLException{
+ assertSingleValue("values timestamp('2010-04-21 12:00:00.123456789')",
+ "2010-04-21 12:00:00.123456789");
+ }
+
+ /**
* Execute an SQL statement and check that it returns a single, specific
* value.
*