db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1447996 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/SQLDouble.java engine/org/apache/derby/iapi/types/SQLReal.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
Date Wed, 20 Feb 2013 04:19:02 GMT
Author: dag
Date: Wed Feb 20 04:19:02 2013
New Revision: 1447996

URL: http://svn.apache.org/r1447996
Log:
DERBY-5546 ResultSet#updateBigDecimal on a REAL column does not do underflow checking 

Patch derby-5546-2. For both Real and Double, check for underflow. For
Double underflow is currently detected but only because we didn't fix
DERBY-3398 yet, so we introduce the same check now as for Real.  Once
DERBY-3398 it will no longer be redundant. The tests are still guarded
by a check for embedded until DERBY-5534 is fixed.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDouble.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLReal.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDouble.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDouble.java?rev=1447996&r1=1447995&r2=1447996&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDouble.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDouble.java Wed Feb 20
04:19:02 2013
@@ -36,6 +36,7 @@ import java.io.ObjectOutput;
 import java.io.ObjectInput;
 import java.io.IOException;
 
+import java.math.BigDecimal;
 import java.sql.ResultSet;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
@@ -442,8 +443,24 @@ public final class SQLDouble extends Num
 		// Note BigDecimal.doubleValue() handles the case where
 		// its value is outside the range of a double. It returns
 		// infinity values which should throw an exception in setValue(double).
-		setValue(bigDecimal.doubleValue());
-		
+
+        double v = bigDecimal.doubleValue();
+
+        if (v == 0) {
+            // We need to catch underflow here, since BigDecimal#doubleValue it
+            // just returns 0 (i.e. no exception).
+            boolean isZero =
+                ((BigDecimal) bigDecimal).compareTo(BigDecimal.ZERO) == 0;
+
+            if (!isZero) {
+                throw StandardException.
+                    newException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE,
+                                 TypeId.REAL_NAME);
+            }
+        }
+
+        setValue(v);
+
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLReal.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLReal.java?rev=1447996&r1=1447995&r2=1447996&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLReal.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLReal.java Wed Feb 20 04:19:02
2013
@@ -36,6 +36,7 @@ import java.io.ObjectOutput;
 import java.io.ObjectInput;
 import java.io.IOException;
 
+import java.math.BigDecimal;
 import java.sql.ResultSet;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
@@ -398,9 +399,25 @@ public final class SQLReal
 
 		// Note BigDecimal.floatValue() handles the case where
 		// its value is outside the range of a float. It returns
-		// infinity values which should throw an exception in setValue(double).
-		setValue(bigDecimal.floatValue());
-		
+        // infinity values which should throw an exception in setValue(float).
+
+        float v = bigDecimal.floatValue();
+
+        if (v == 0) {
+            // We need to catch underflow here, since BigDecimal#floatValue it
+            // just returns 0 (i.e. no exception).
+            boolean isZero =
+                ((BigDecimal) bigDecimal).compareTo(BigDecimal.ZERO) == 0;
+
+            if (!isZero) {
+                throw StandardException.
+                    newException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE,
+                                 TypeId.REAL_NAME);
+            }
+        }
+
+        setValue(v);
+
 	}
 
 	public void setValue(float theValue)

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java?rev=1447996&r1=1447995&r2=1447996&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
Wed Feb 20 04:19:02 2013
@@ -4758,11 +4758,11 @@ public class ParameterMappingTest extend
         }
 
         // REAL Underflow checking
-        //
-        // Uncomment when DERBY-5546 is fixed:
-        // assertUpdateState(rs, "F04", bdSmallestPosDoubleValue, "22003");
-        // assertUpdateState(rs, "F04", bdSmallestNegDoubleValue, "22003");
-
+        // Remove test when DERBY-5534 is fixed
+        if (usingEmbedded()) {
+            assertUpdateState(rs, "F04", bdSmallestPosDoubleValue, "22003");
+            assertUpdateState(rs, "F04", bdSmallestNegDoubleValue, "22003");
+        }
 
         // DOUBLE, FLOAT (SQL FLOAT is really the same as SQL DOUBLE in Derby)
         final String[] dfCols = new String[]{"F05", "F06"};
@@ -4802,12 +4802,13 @@ public class ParameterMappingTest extend
             }
 
             // DOUBLE, FLOAT underflow checking
-            //
-            // Uncomment when DERBY-5546 is fixed
-            // assertUpdateState(rs, dfCols[i],
-            //     bdSmallestPosDoubleValue.divide(BigDecimal.TEN), "22003");
-            // assertUpdateState(rs, dfCols[i],
-            //     bdSmallestNegDoubleValue.divide(BigDecimal.TEN), "22003");
+            // Remove test when DERBY-5534 is fixed
+            if (usingEmbedded()) {
+                assertUpdateState(rs, dfCols[i],
+                    bdSmallestPosDoubleValue.divide(BigDecimal.TEN), "22003");
+                assertUpdateState(rs, dfCols[i],
+                    bdSmallestNegDoubleValue.divide(BigDecimal.TEN), "22003");
+            }
         }
 
         // Derby BOOLEAN: not range checked: FALSE of 0, else TRUE.



Mime
View raw message