db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1428256 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Thu, 03 Jan 2013 10:04:44 GMT
Author: kahatlen
Date: Thu Jan  3 10:04:44 2013
New Revision: 1428256

URL: http://svn.apache.org/viewvc?rev=1428256&view=rev
Log:
DERBY-2516: Network Client allows execution of callable statement when one of the parameters
is not set

Check that INOUT parameters are set, not only registered with registerOutParam().

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java

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?rev=1428256&r1=1428255&r2=1428256&view=diff
==============================================================================
--- 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 Thu
Jan  3 10:04:44 2013
@@ -2422,7 +2422,14 @@ public class PreparedStatement extends S
     private void checkThatAllParametersAreSet() throws SqlException {
         if (parameterMetaData_ != null) {
             for (int i = 0; i < parameterMetaData_.columns_; i++) {
-                if (!parameterSet_[i] && !parameterRegistered_[i]) {
+                // Raise an exception if at least one of the parameters isn't
+                // set. It is OK that a parameter isn't set if it is registered
+                // as an output parameter. However, if it's an INOUT parameter,
+                // it must be set even if it has been registered (DERBY-2516).
+                if (!parameterSet_[i] &&
+                        (!parameterRegistered_[i] ||
+                         parameterMetaData_.sqlxParmmode_[i] ==
+                            java.sql.ParameterMetaData.parameterModeInOut)) {
                     throw new SqlException(agent_.logWriter_, 
                         new ClientMessageId(SQLState.LANG_MISSING_PARMS));
                 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java?rev=1428256&r1=1428255&r2=1428256&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java
Thu Jan  3 10:04:44 2013
@@ -815,6 +815,51 @@ public class ProcedureTest extends BaseJ
              );
     }
 
+    /**
+     * Regression test case for DERBY-2516. If an INOUT parameter had been
+     * registered as an output parameter, but no input value had been assigned
+     * to it, the client driver would go ahead and execute the statement
+     * using null as input.
+     */
+    public void testInOutParamNotSet() throws SQLException {
+        setAutoCommit(false);
+
+        Statement s = createStatement();
+        s.execute("create procedure proc_2516 (inout i int) " +
+                  "language java parameter style java external name '" +
+                  getClass().getName() + ".proc_2516' no sql");
+
+        // Register an INOUT parameter, but don't set it. Expect failure.
+        // Client used to execute without error.
+        CallableStatement cs = prepareCall("call proc_2516(?)");
+        cs.registerOutParameter(1, Types.INTEGER);
+        assertStatementError("07000", cs);
+
+        // Should work if the parameter has been set.
+        cs.setInt(1, 0);
+        cs.execute();
+        assertEquals(10, cs.getInt(1));
+
+        // After clearing the parameters, execution should fail. Client used
+        // to succeed.
+        cs.clearParameters();
+        assertStatementError("07000", cs);
+
+        // Setting the parameter again should make it work.
+        cs.setInt(1, 1);
+        cs.execute();
+        assertEquals(10, cs.getInt(1));
+    }
+
+    /**
+     * Stored procedure used by the regression test case for DERBY-2516.
+     *
+     * @param i INOUT parameter that gets set to 10 by the procedure
+     */
+    public static void proc_2516(Integer[] i) {
+        i[0] = new Integer(10);
+    }
+
     // UTILITY METHODS
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java?rev=1428256&r1=1428255&r2=1428256&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java
Thu Jan  3 10:04:44 2013
@@ -1748,17 +1748,14 @@ public class LangProcedureTest extends B
         } catch (SQLException sqle) {
             assertSQLState("07000", sqle);
         }
-        if (usingEmbedded()) {
-            // Do not run for client until DERBY-2516 is fixed
-            op.clearParameters();
-            op.setString(2, "2");
-            try {
-                // a not set
-                op.execute();
-                fail("FAIL - a  not set");
-            } catch (SQLException sqle) {
-                assertSQLState("07000", sqle);
-            }
+        op.clearParameters();
+        op.setString(2, "2");
+        try {
+            // a not set
+            op.execute();
+            fail("FAIL - a  not set");
+        } catch (SQLException sqle) {
+            assertSQLState("07000", sqle);
         }
         op.clearParameters();
         op.setBigDecimal(1, new BigDecimal("33"));



Mime
View raw message