You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by bp...@apache.org on 2016/11/19 01:43:08 UTC
svn commit: r1770458 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ParameterMappingTest.java
Author: bpendleton
Date: Sat Nov 19 01:43:08 2016
New Revision: 1770458
URL: http://svn.apache.org/viewvc?rev=1770458&view=rev
Log:
DERBY-6902: Value out of range error
This change adds still more new test cases to ParameterMappingTest, derived
from the original scenario described in the issue.
The new test cases explore some datatype conversions from string-to-integer.
They also look at some other variations on the original query from the
issue, demonstrating that the details of the phrasing of the query affect
the query compiler's decisions about intermediate data types.
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=1770458&r1=1770457&r2=1770458&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 Sat Nov 19 01:43:08 2016
@@ -5031,6 +5031,59 @@ public class ParameterMappingTest extend
ps6902.setLong(1, 1470362049757L);
ps6902.executeUpdate();
+
+ try {
+ ps6902.setString( 1, "abcde" );
+ ps6902.executeUpdate();
+ fail("expected setString to fail with non-numeric string");
+ } catch (SQLException e) {
+ assertSQLState( "22018", e );
+ }
+
+ // Use setString to set integer values, both small and large,
+ // into the statement using CAST to make the parameter BIGINT:
+
+ ps6902.setString(1, "1479058636" ); // value < Integer.MAX_VALUE
+ ps6902.executeUpdate();
+
+ ps6902.setString(1, "1470362049757" );
+ ps6902.executeUpdate();
+
+ try {
+ ps6902 = prepareStatement(
+ "delete from test6902 where small_number * 1000 > ?" );
+ ps6902.setLong( 1, 1470362049757L);
+ ps6902.executeUpdate();
+ fail("Expected out of range exception.");
+ } catch (SQLException e) {
+ assertSQLState( "22003", e );
+ }
+
+ // Algebraically re-formulate the original query:
+
+ ps6902 = prepareStatement(
+ "delete from test6902 " +
+ " where big_number + small_number * 1000 < ?" );
+ ps6902.setLong( 1, 1470362049757L);
+ ps6902.executeUpdate();
+
+ // Without casts, use setString to set integer values,
+ // small and large:
+
+ ps6902 = prepareStatement(
+ "delete from test6902 " +
+ " where big_number < ? - small_number * 1000" );
+
+ ps6902.setString(1, "1479058636" ); // value < Integer.MAX_VALUE
+ ps6902.executeUpdate();
+
+ try {
+ ps6902.setString(1, "1470362049757" );
+ ps6902.executeUpdate();
+ fail("expected setString to fail with numeric string > INT_MAX");
+ } catch (SQLException e) {
+ assertSQLState( "22018", e );
+ }
}
// Short limits