db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r1069959 - in /db/derby/code/branches/10.5/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
Date Fri, 11 Feb 2011 21:29:16 GMT
Author: mikem
Date: Fri Feb 11 21:29:16 2011
New Revision: 1069959

URL: http://svn.apache.org/viewvc?rev=1069959&view=rev
Log:
DERBY-4625: TIMESTAMP function doesn't accept nanoseconds

backported change #999479 from trunk to 10.5 branch.

Patch contributed by C.S. Nirmal J. Fernando <nirmal070125@gmail.com>. 


Modified:
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.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

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java?rev=1069959&r1=1069958&r2=1069959&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java Fri Feb
11 21:29:16 2011
@@ -1569,19 +1569,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/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=1069959&r1=1069958&r2=1069959&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 Feb 11 21:29:16 2011
@@ -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/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=1069959&r1=1069958&r2=1069959&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 Feb 11 21:29:16 2011
@@ -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.
      *



Mime
View raw message