db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1229481 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
Date Tue, 10 Jan 2012 07:54:41 GMT
Author: dag
Date: Tue Jan 10 07:54:40 2012
New Revision: 1229481

URL: http://svn.apache.org/viewvc?rev=1229481&view=rev
Log:
DERBY-5536 Client's ResultSet#getLong does not range check when converting from a DECIMAL
column

Followup patch "derby-5536-refactor" factors out the test cases for
DERBY-5536 into a separate fixture, adding "ORDER BY" to secure
correct row retrieval order.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java

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=1229481&r1=1229480&r2=1229481&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
Tue Jan 10 07:54:40 2012
@@ -4566,69 +4566,6 @@ public class ParameterMappingTest extend
         assertGetState(rs, "F07", XXX_LONG, "22003");
         rs.close();
 
-        // DERBY-5536: client driver change of implementation for getting long
-        // from DECIMAL, so check correctness for two cases: 1) value with 18
-        // decimal digits or less, and 2) value with more than 18 decimal
-        // digits. Reason: cross-over point in implementation; the smaller
-        // numbers use an optimized code path.  Also try with and without
-        // non-zero fraction to see what happens to the discarded fractional
-        // part (scale == 1): Conversions to long should round off in the
-        // direction of zero for both positive and negative numbers with a
-        // fractional part >< 0, cf. RoundingMode.DOWN used in the asserts
-        // below.
-
-        BigDecimal vBelow[] =
-            new BigDecimal[]{new BigDecimal(123456789012345678L),  // 18 digits
-                             new BigDecimal(-12345678901234567L)};
-
-        BigDecimal vAbove[] =
-            new BigDecimal[]{new BigDecimal(1234567890123456789L), // 19 digits
-                             new BigDecimal(-123456789012345678L)};
-
-        createStatement().executeUpdate(
-            "create table t5536(d1 decimal(19,1)," +
-            "                   d2 decimal(20,1))");
-        PreparedStatement ps5536 = prepareStatement(
-            "insert into t5536 values (?,?)");
-
-        for (int scale=0; scale < 2; scale++) {
-            for (int i=0; i < vBelow.length; i++) {
-                ps5536.setBigDecimal(
-                    1,
-                    new BigDecimal(vBelow[i].toBigInteger(), scale));
-                ps5536.setBigDecimal(
-                    2,
-                    new BigDecimal(vAbove[i].toBigInteger(), scale));
-
-                ps5536.execute();
-            }
-        }
-
-
-
-        rs = createStatement().executeQuery("select * from t5536");
-
-        BigDecimal divisor[] = {BigDecimal.ONE, BigDecimal.TEN};
-
-        for (int scale=0; scale < 2; scale++) {
-            for (int i=0; i < vBelow.length; i++) {
-                rs.next();
-
-                assertEquals(
-                    "round-trip conversion error",
-                    vBelow[i].divide(divisor[scale], RoundingMode.DOWN).
-                        longValue(),
-                    rs.getLong(1));
-                assertEquals(
-                    "round-trip conversion error",
-                    vAbove[i].divide(divisor[scale], RoundingMode.DOWN).
-                        longValue(),
-                    rs.getLong(2));
-            }
-        }
-
-        rs.close();
-
 
         // JDBC type -> float
         PreparedStatement uSelect = prepareStatement(
@@ -4914,6 +4851,77 @@ public class ParameterMappingTest extend
         // assertUpdateState(rs, "F11", new BigDecimal(2), "22003");
     }
 
+    /**
+     * DERBY-5536: client driver change of implementation for getting long
+     * from DECIMAL, so check correctness for two cases: 1) value with 18
+     * decimal digits or less, and 2) value with more than 18 decimal
+     * digits. Reason: cross-over point in implementation; the smaller
+     * numbers use an optimized code path.  Also try with and without
+     * non-zero fraction to see what happens to the discarded fractional
+     * part (scale == 1): Conversions to long should round off in the
+     * direction of zero for both positive and negative numbers with a
+     * fractional part >< 0, cf. RoundingMode.DOWN used in the asserts
+     * below.
+     */
+    public void testDerby5536() throws SQLException {
+
+        BigDecimal vBelow[] =
+            new BigDecimal[]{new BigDecimal(123456789012345678L),  // 18 digits
+                             new BigDecimal(-12345678901234567L)};
+
+        BigDecimal vAbove[] =
+            new BigDecimal[]{new BigDecimal(1234567890123456789L), // 19 digits
+                             new BigDecimal(-123456789012345678L)};
+
+        createStatement().executeUpdate(
+            "create table t5536(d1 decimal(19,1)," +
+            "                   d2 decimal(20,1)," +
+            "                   i int generated always as identity" +
+            "                         (start with 1, increment by 1))");
+        PreparedStatement ps5536 = prepareStatement(
+            "insert into t5536 values (?, ?, default)");
+
+        for (int scale=0; scale < 2; scale++) {
+            for (int i=0; i < vBelow.length; i++) {
+                ps5536.setBigDecimal(
+                    1,
+                    new BigDecimal(vBelow[i].toBigInteger(), scale));
+                ps5536.setBigDecimal(
+                    2,
+                    new BigDecimal(vAbove[i].toBigInteger(), scale));
+
+                ps5536.execute();
+            }
+        }
+
+
+
+        ResultSet rs = createStatement().executeQuery(
+            "select * from t5536 order by i");
+
+        BigDecimal divisor[] = {BigDecimal.ONE, BigDecimal.TEN};
+
+        for (int scale=0; scale < 2; scale++) {
+            for (int i=0; i < vBelow.length; i++) {
+                rs.next();
+
+                assertEquals(
+                    "round-trip conversion error",
+                    vBelow[i].divide(divisor[scale], RoundingMode.DOWN).
+                        longValue(),
+                    rs.getLong(1));
+                assertEquals(
+                    "round-trip conversion error",
+                    vAbove[i].divide(divisor[scale], RoundingMode.DOWN).
+                        longValue(),
+                    rs.getLong(2));
+            }
+        }
+
+        rs.close();
+    }
+
+
     // Short limits
     //
     private final static BigDecimal bdMaxShortValue =



Mime
View raw message