db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r438037 - in /db/derby/code/branches/10.2/java: client/org/apache/derby/client/am/PreparedStatement.java testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java
Date Tue, 29 Aug 2006 09:58:18 GMT
Author: kahatlen
Date: Tue Aug 29 02:58:18 2006
New Revision: 438037

URL: http://svn.apache.org/viewvc?rev=438037&view=rev
Log:
DERBY-1292: ClassCastException in ClientDriver when using CLOB columns
and batch updates

Merged fix from trunk.

Modified:
    db/derby/code/branches/10.2/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java

Modified: db/derby/code/branches/10.2/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=438037&r1=438036&r2=438037&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/client/org/apache/derby/client/am/PreparedStatement.java
(original)
+++ db/derby/code/branches/10.2/java/client/org/apache/derby/client/am/PreparedStatement.java
Tue Aug 29 02:58:18 2006
@@ -27,6 +27,7 @@
 import java.io.InputStream;
 import java.io.Reader;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import org.apache.derby.client.ClientPooledConnection;
 import org.apache.derby.jdbc.ClientDriver;
 
@@ -62,6 +63,8 @@
     }
 
     public ColumnMetaData parameterMetaData_; // type information for input sqlda
+    
+    private ArrayList parameterTypeList;
 
 
     // The problem with storing the scrollable ResultSet associated with cursorName in scrollableRS_
is
@@ -86,6 +89,7 @@
         parameterSet_ = null;
         parameterRegistered_ = null;
         parameterMetaData_ = null;
+        parameterTypeList = null;
         isAutoCommittableStatement_ = true;
         isPreparedStatement_ = true;
     }
@@ -1361,6 +1365,10 @@
                 }
                 checkForClosedStatement();
                 checkThatAllParametersAreSet();
+                
+                if (parameterTypeList == null) {
+                    parameterTypeList = new ArrayList();
+                }
 
                 // ASSERT: since OUT/INOUT parameters are not allowed, there should
                 //         be no problem in sharing the JDBC Wrapper object instances
@@ -1373,8 +1381,13 @@
                     System.arraycopy(parameters_, 0, inputsClone, 0, parameters_.length);
 
                     batch_.add(inputsClone);
+                    
+                    // Get a copy of the parameter type data and save it in a list
+                    // which will be used later on at the time of batch execution.
+                    parameterTypeList.add(parameterMetaData_.clientParamtertype_.clone());
                 } else {
                     batch_.add(null);
+                    parameterTypeList.add(null);
                 }
             }
         }
@@ -2027,6 +2040,7 @@
         }
 
         for (int i = 0; i < batchSize; i++) {
+            parameterMetaData_.clientParamtertype_ = (int[]) parameterTypeList.get(i);
             parameters_ = (Object[]) batch_.get(i);
 
             if (sqlMode_ != isCall__) {
@@ -2115,6 +2129,7 @@
         }
         // We need to clear the batch before any exception is thrown from agent_.endBatchedReadChain().
         batch_.clear();
+        parameterTypeList = null;
 
         // restore the saved input set, setting it to "current"
         parameters_ = savedInputs;

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java?rev=438037&r1=438036&r2=438037&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java
Tue Aug 29 02:58:18 2006
@@ -30,6 +30,7 @@
 import java.sql.Date;
 import java.sql.Time;
 import java.sql.Timestamp;
+import java.sql.Types;
 import java.sql.SQLException;
 import java.sql.BatchUpdateException;
 import java.io.ByteArrayInputStream; 
@@ -49,7 +50,7 @@
     private static String[] testObjects =  // string array for cleaning up
         {"table t1", "table tab1", "table t2", "table bigtab", "table tstab",
          "table doubletab", "table numtab", "table Numeric_Tab", "table jira614", 
-	 "table jira614_a", "table jira428", "table jira125", 
+	 "table jira614_a", "table jira428", "table jira125", "table varcharclobtab", 
          "table jira125125125125125125125125125125125125125125125125125125125125125125125125125125125125125125125",
          "table jira1533_a", "table jira1533_b"};
 
@@ -309,6 +310,10 @@
 
 			testBigDecimalSetObject(conn);
 			testBigDecimalSetObjectWithScale(conn);
+            
+			if (!TestUtil.isJCCFramework()) {
+				testVaryingClientParameterTypeBatch(conn);
+			}
 
 			test4975(conn);
 			test5130(conn);
@@ -335,6 +340,36 @@
 			e.printStackTrace();
 		}
 	}
+    
+    // Test execution of batch update where the type of
+    // a parameter varies for difference entries in the batch.
+    private static void testVaryingClientParameterTypeBatch(Connection conn) throws Exception
+    {
+        Statement stmt = conn.createStatement();
+
+        try { stmt.execute("drop table varcharclobtab"); } catch (Throwable t) { }
+        stmt.execute("create table varcharclobtab (c1 varchar(100), c2 clob)");
+        stmt.close();
+        
+        PreparedStatement pStmt = conn.prepareStatement("insert into varcharclobtab VALUES(?,?)");
+
+        pStmt.setNull(1, Types.VARCHAR);
+        pStmt.setString(2, "clob");
+        pStmt.addBatch();
+        
+        pStmt.setString(1, "varchar");
+        pStmt.setNull(2, Types.CLOB);
+        pStmt.addBatch();
+     
+        // The following statement should not throw an exception.
+        try {
+            pStmt.executeBatch();
+        } catch (ClassCastException e) {
+            System.out.println("FAIL: ClassCastException thrown by testVaryingClientParameterTypeBatch
test.");
+            throw e;
+        }
+        pStmt.close();
+    }
 
 	// Test creation and execution of many Prepared Statements
 	// Beetle 5130



Mime
View raw message