db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1058478 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java
Date Thu, 13 Jan 2011 09:51:18 GMT
Author: kahatlen
Date: Thu Jan 13 09:51:18 2011
New Revision: 1058478

URL: http://svn.apache.org/viewvc?rev=1058478&view=rev
Log:
DERBY-4970: ClassCastException from getBlob()/getClob() in EmbedCallableStatement

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java?rev=1058478&r1=1058477&r2=1058478&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedCallableStatement.java
Thu Jan 13 09:51:18 2011
@@ -574,16 +574,13 @@ public abstract class EmbedCallableState
      * @exception SQLException if a database-access error occurs.
      */
     public Blob getBlob (int parameterIndex) throws SQLException {
-		checkStatus();
-		try {
-			DataValueDescriptor param = getParms().getParameterForGet(parameterIndex-1);
-			Blob v = (Blob) param.getObject();
-			wasNull = (v == null);
-			return v;
-		} catch (StandardException e)
-		{
-			throw EmbedResultSet.noStateChangeException(e);
-		}
+        Object o = getObject(parameterIndex);
+        if (o == null || o instanceof Blob) {
+            return (Blob) o;
+        }
+        throw newSQLException(SQLState.LANG_DATA_TYPE_GET_MISMATCH,
+                Blob.class.getName(),
+                Util.typeName(getParameterJDBCType(parameterIndex)));
     }
 
     /**
@@ -596,16 +593,13 @@ public abstract class EmbedCallableState
      * @exception SQLException if a database-access error occurs.
      */
     public Clob getClob (int parameterIndex) throws SQLException {
-		checkStatus();
-		try {
-			DataValueDescriptor param = getParms().getParameterForGet(parameterIndex-1);
-			Clob v = (Clob) param.getObject();
-			wasNull = (v == null);
-			return v;
-		} catch (StandardException e)
-		{
-			throw EmbedResultSet.noStateChangeException(e);
-		}
+        Object o = getObject(parameterIndex);
+        if (o == null || o instanceof Clob) {
+            return (Clob) o;
+        }
+        throw newSQLException(SQLState.LANG_DATA_TYPE_GET_MISMATCH,
+                Clob.class.getName(),
+                Util.typeName(getParameterJDBCType(parameterIndex)));
     }
     
 	public void addBatch() throws SQLException {

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=1058478&r1=1058477&r2=1058478&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 13 09:51:18 2011
@@ -26,6 +26,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Types;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -593,6 +594,40 @@ public class ProcedureTest extends BaseJ
         JDBC.assertNoMoreResults(ps);
     }
 
+    /**
+     * Test that a call to getBlob() to retrieve the value of a non-BLOB
+     * parameter fails with the expected SQLException. Used to throw
+     * ClassCastException, see DERBY-4970.
+     */
+    public void testGetBlobFromIntParameter() throws SQLException {
+        CallableStatement cs = prepareCall("call int_out(?)");
+        cs.registerOutParameter(1, Types.INTEGER);
+        cs.execute();
+        try {
+            cs.getBlob(1);
+            fail("getBlob() on int parameter expected to fail");
+        } catch (SQLException sqle) {
+            assertSQLState("22005", sqle);
+        }
+    }
+
+    /**
+     * Test that a call to getClob() to retrieve the value of a non-CLOB
+     * parameter fails with the expected SQLException. Used to throw
+     * ClassCastException, see DERBY-4970.
+     */
+    public void testGetClobFromIntParameter() throws SQLException {
+        CallableStatement cs = prepareCall("call int_out(?)");
+        cs.registerOutParameter(1, Types.INTEGER);
+        cs.execute();
+        try {
+            cs.getClob(1);
+            fail("getClob() on int parameter expected to fail");
+        } catch (SQLException sqle) {
+            assertSQLState("22005", sqle);
+        }
+    }
+
     // UTILITY METHODS
 
     /**
@@ -737,8 +772,11 @@ public class ProcedureTest extends BaseJ
           "CREATE PROCEDURE NESTED_RESULT_SETS(proctext VARCHAR(128)) LANGUAGE JAVA " +
           "PARAMETER STYLE JAVA EXTERNAL NAME '" +
           ProcedureTest.class.getName() + ".nestedDynamicResultSets' " +
-          "DYNAMIC RESULT SETS 6"
+          "DYNAMIC RESULT SETS 6",
 
+          "CREATE PROCEDURE INT_OUT(OUT X INTEGER) LANGUAGE JAVA " +
+          "PARAMETER STYLE JAVA EXTERNAL NAME '" +
+          ProcedureTest.class.getName() + ".intOut'",
     };
 
     /**
@@ -888,6 +926,13 @@ public class ProcedureTest extends BaseJ
     
     }
 
+    /**
+     * Stored procedure with an integer output parameter.
+     * @param out an output parameter
+     */
+    public static void intOut(int[] out) {
+        out[0] = 42;
+    }
     
         /**
          * Test various combinations of getMoreResults



Mime
View raw message