db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r538413 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/ testing/org/apache/derbyTesting/functionTests/tes...
Date Wed, 16 May 2007 02:59:33 GMT
Author: bpendleton
Date: Tue May 15 19:59:32 2007
New Revision: 538413

URL: http://svn.apache.org/viewvc?view=rev&rev=538413
Log:
DERBY-2558: Client throws JDK exception rather than parameter out of range

The client implementation throws an ArrayIndexOutOfBoundsException rather
than the expected: ERROR XCL13: The parameter position '2' is out of range.
The number of parameters for this prepared statement is '1'. 

The issue is that the 4-argument overload of setObject was missing the
code to validate the parameterIndex; this code is present in the other
overloads of setObject.

This change adds the parameterIndex validation call, and also adds tests.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij2.sql

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?view=diff&rev=538413&r1=538412&r2=538413
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Tue
May 15 19:59:32 2007
@@ -1488,6 +1488,7 @@
                             Object x,
                             int targetJdbcType,
                             int scale) throws SqlException {
+        checkForValidParameterIndex(parameterIndex);
         checkForValidScale(scale);
 
         // JDBC 4.0 requires us to throw SQLFeatureNotSupportedException for

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out?view=diff&rev=538413&r1=538412&r2=538413
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij2.out
Tue May 15 19:59:32 2007
@@ -91,6 +91,25 @@
 ij> -- note that the using part was, however, executed...
 drop table s;
 0 rows inserted/updated/deleted
+ij> -- DERBY-2558: Verify that we get a reasonable message when the 'dimension'
+-- of the 'using-set' does not match the 'dimension' of the prepared statement:
+create table t2558 (i int);
+0 rows inserted/updated/deleted
+ij> insert into t2558 values (3), (4);
+2 rows inserted/updated/deleted
+ij> -- First two statements below should fail. Third one should work.
+execute 'select * from t2558 where i = ?' using 'values (3,4)';
+IJ WARNING: Autocommit may close using result set
+ERROR XCL13: The parameter position '2' is out of range.  The number of parameters for this
prepared  statement is '1'.
+ij> execute 'select * from t2558 where i in (?,?,?)' using 'values (3,4)';
+IJ WARNING: Autocommit may close using result set
+ERROR 07000: At least one parameter to the current statement is uninitialized.
+ij> execute 'select * from t2558 where i = ? or i = ?' using 'values (3,4)';
+IJ WARNING: Autocommit may close using result set
+I          
+-----------
+3          
+4          
 ij> -- bug 5926 - make sure the using clause result set got closed
 drop table t;
 0 rows inserted/updated/deleted

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java?view=diff&rev=538413&r1=538412&r2=538413
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/PrepareStatementTest.java
Tue May 15 19:59:32 2007
@@ -288,6 +288,29 @@
             assertSQLState("07000", e);
         }
         pSt.close();
+
+        // Some test cases for DERBY-2558, involving validation of the
+        // parameterIndex argument to the 4-argument overload of setObject
+        //
+        pSt = prepareStatement("create table d2558 (i int)");
+        assertUpdateCount(pSt, 0);
+        pSt.close();
+        pSt = prepareStatement("insert into d2558 values (3), (4)");
+        assertUpdateCount(pSt, 2);
+        pSt.close();
+        pSt = prepareStatement("select * from d2558 where i = ?");
+        pSt.setObject(1,new Integer(3),java.sql.Types.INTEGER,0);
+        try {
+            // There's only 1 parameter marker, so this should fail:
+            pSt.setObject(2,new Integer(4), java.sql.Types.INTEGER,0);
+            rs = pSt.executeQuery();
+            rs.close();
+            fail("Exception expected above!");
+        } catch (SQLException e) {
+            assertSQLState("XCL13", e);
+        }
+        pSt.close();
+
     }
 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij2.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij2.sql?view=diff&rev=538413&r1=538412&r2=538413
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij2.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij2.sql
Tue May 15 19:59:32 2007
@@ -67,6 +67,15 @@
 -- note that the using part was, however, executed...
 drop table s;
 
+-- DERBY-2558: Verify that we get a reasonable message when the 'dimension'
+-- of the 'using-set' does not match the 'dimension' of the prepared statement:
+create table t2558 (i int);
+insert into t2558 values (3), (4);
+-- First two statements below should fail. Third one should work.
+execute 'select * from t2558 where i = ?' using 'values (3,4)';
+execute 'select * from t2558 where i in (?,?,?)' using 'values (3,4)';
+execute 'select * from t2558 where i = ? or i = ?' using 'values (3,4)';
+
 -- bug 5926 - make sure the using clause result set got closed
 drop table t;
 create table t(c1 int);



Mime
View raw message