db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1511185 - in /db/derby/code/branches/10.9: ./ java/engine/org/apache/derby/iapi/types/ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Wed, 07 Aug 2013 06:00:09 GMT
Author: mamta
Date: Wed Aug  7 06:00:09 2013
New Revision: 1511185

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

Backporting to 10.9

Fix provided by Dag Wanvik


Modified:
    db/derby/code/branches/10.9/   (props changed)
    db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLDouble.java
    db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLReal.java
    db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java

Propchange: db/derby/code/branches/10.9/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1447996

Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLDouble.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLDouble.java?rev=1511185&r1=1511184&r2=1511185&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLDouble.java (original)
+++ db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLDouble.java Wed
Aug  7 06:00:09 2013
@@ -46,6 +46,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;
@@ -459,8 +460,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/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLReal.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLReal.java?rev=1511185&r1=1511184&r2=1511185&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLReal.java (original)
+++ db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/SQLReal.java Wed Aug
 7 06:00:09 2013
@@ -46,6 +46,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;
@@ -414,9 +415,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/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java?rev=1511185&r1=1511184&r2=1511185&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
(original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
Wed Aug  7 06:00:09 2013
@@ -4764,11 +4764,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"};
@@ -4808,12 +4808,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