db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1769904 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
Date Wed, 16 Nov 2016 01:07:29 GMT
Author: bpendleton
Date: Wed Nov 16 01:07:29 2016
New Revision: 1769904

URL: http://svn.apache.org/viewvc?rev=1769904&view=rev
Log:
DERBY-6902: Value out of range error

This change adds several new test cases to ParameterMappingTest, derived
from the original scenario described in the issue.

These test cases are designed to demonstrate the particular exception
discussed in the issue, as well as to demonstrate several ways to use
a CAST operator so that the query executes as desired.


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=1769904&r1=1769903&r2=1769904&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 Nov 16 01:07:29 2016
@@ -4987,6 +4987,51 @@ public class ParameterMappingTest extend
         rs.close();
     }
 
+    public void testDerby6902()
+        throws SQLException
+    {
+        createStatement().executeUpdate(
+            "create table test6902 (" +
+            "  id bigint primary key," +
+            "  big_number bigint not null," +
+            "  small_number int not null" +
+            ")" );
+
+        PreparedStatement ps6902 = prepareStatement(
+            "delete from test6902 " +
+            "  where big_number < ? - small_number * 1000" );
+
+        try {
+            ps6902.setLong(1, 1470362049757L);
+            ps6902.executeUpdate();
+            fail("without cast, expected setLong to fail");
+        } catch (SQLException e) {
+            assertSQLState( "22003", e );
+        }
+
+        ps6902.setLong(1, 1479058636L); // value < Integer.MAX_VALUE
+        ps6902.executeUpdate();
+
+	// Use a cast on integer column small_number:
+
+        ps6902 = prepareStatement(
+            "delete from test6902 " +
+            "  where big_number < " +
+            "        ? - cast( small_number as bigint) * 1000" );
+
+        ps6902.setLong(1, 1470362049757L);
+        ps6902.executeUpdate();
+
+	// Use a cast on the parameter marker itself:
+
+        ps6902 = prepareStatement(
+            "delete from test6902 " +
+            "  where big_number < " +
+            "        cast( ? as bigint) - small_number * 1000" );
+
+        ps6902.setLong(1, 1470362049757L);
+        ps6902.executeUpdate();
+    }
 
     // Short limits
     //



Mime
View raw message