db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1488453 - /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java
Date Sat, 01 Jun 2013 02:32:00 GMT
Author: mamta
Date: Sat Jun  1 02:32:00 2013
New Revision: 1488453

URL: http://svn.apache.org/r1488453
Log:
DERBY-6237(PreparedStatement.execute() fails starting 10.2 when multiple rows are updated
and PreparedStatement.setCharacterStream(int, Reader, int) is used)

This commit adds test case for updating more than one row with setCharacterStream to update
VARCHAR column in the underlying table. The test is commented out at this point since it does
not work in 10.2. Once this jira is fixed in 10.2, we should uncomment these tests. This test
case works fine in 10.1



Modified:
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java?rev=1488453&r1=1488452&r2=1488453&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java
Sat Jun  1 02:32:00 2013
@@ -3056,7 +3056,7 @@ public class parameterMapping {
 
         //Following will update one or 2 rows depending on the 1st param
         PreparedStatement ps = conn.prepareStatement(
-            "UPDATE TestUpdateCharStream SET c3 = ?, " + 
+            "UPDATE TestUpdateCharStream SET c3 = ?, c4 = ?, " + 
             "c2 = c2 + 1 WHERE c1 IN (?, ?)");
 
         switch (testVariation) {
@@ -3064,33 +3064,37 @@ public class parameterMapping {
         	//test short data
             ps.setCharacterStream(1,
                     new LoopingAlphabetReader(50, a1), 50);
+            ps.setCharacterStream(2,
+                    new LoopingAlphabetReader(50, a1), 50);
             break;
         case 2 :
         	//test large data
             ps.setCharacterStream(1,
                     new LoopingAlphabetReader(50000, a1), 50000);
+            ps.setCharacterStream(2,
+                    new LoopingAlphabetReader(32000, a1), 32000);
             break;
         }
         
         //First value in IN clause is getting set to 'AAAAA'
         // Using setCharacterStream on VARCHAR to set the value
-        ps.setCharacterStream(2, new CharArrayReader("AAAAA".toCharArray()), 5);
+        ps.setCharacterStream(3, new CharArrayReader("AAAAA".toCharArray()), 5);
         
         if (numberOfRowsToUpdate == 1 ) {
             //Second value in IN clause is also getting set to 'AAAAA', which 
             // means prepared statement will update only one row
-            ps.setObject(3, "AAAAA", Types.VARCHAR);
+            ps.setObject(4, "AAAAA", Types.VARCHAR);
         } else {
             //Second value in IN clause is also getting set to 'EEEEE', which 
             // means prepared statement will update two rows
-            ps.setObject(3, "EEEEE", Types.VARCHAR);
+            ps.setObject(4, "EEEEE", Types.VARCHAR);
         }        	
         ps.execute();
         
         //verify updated data
         ResultSet rs;
         ps = conn.prepareStatement(
-                "select c3 from TestUpdateCharStream " + 
+                "select c3, c4 from TestUpdateCharStream " + 
                 "WHERE c1 IN (?, ?)");
         ps.setCharacterStream(1, new CharArrayReader("AAAAA".toCharArray()), 5);
         if (numberOfRowsToUpdate == 1 ) {
@@ -3099,20 +3103,30 @@ public class parameterMapping {
             ps.setObject(2, "EEEEE", Types.VARCHAR);
         }
     	rs = ps.executeQuery();
-    	char[] c;
+    	char[] c, c1;
     	if (testVariation == 1){
         	//we are here to test short data 
             c = new char[50];
             Arrays.fill(c, 'a'); 
+            c1 = new char[50];
+            Arrays.fill(c1, 'a'); 
     	} else {
         	//we are here to test large data 
             c = new char[50000];
             Arrays.fill(c, 'a');         		
+            c1 = new char[32000];
+            Arrays.fill(c1, 'a');         		
     	}
     	for (int i=0;i<numberOfRowsToUpdate;i++) {
         	rs.next();
         	if (!compareClobReader2CharArray(c,rs.getCharacterStream(1))) {
-    			System.out.println("FAIL: data should have matched");
+    			System.out.println("FAIL: CLOB data should have matched");
+    			rs.close();
+    			ps.close();
+    			return;
+        	}
+        	if (!compareClobReader2CharArray(c1,rs.getCharacterStream(2))) {
+    			System.out.println("FAIL: VARCHAR data should have matched");
     			rs.close();
     			ps.close();
     			return;
@@ -3136,8 +3150,9 @@ public class parameterMapping {
 				totalCharsRead += readChars;
 		} while (readChars != -1 && totalCharsRead < cArray.length);
 		charReader.close();
-		if (!java.util.Arrays.equals(cArray, clobChars))
+		if (!java.util.Arrays.equals(cArray, clobChars)) {
 			return false;
+		}
 
 		return true;
 	}
@@ -3156,7 +3171,8 @@ public class parameterMapping {
         s.executeUpdate("CREATE TABLE TestUpdateCharStream ("+
                 "c1 VARCHAR(64) NOT NULL, " +
           	    "c2 INTEGER, " +
-                "c3 CLOB)"); 
+                "c3 CLOB, " +
+          	    "c4 VARCHAR(32000))"); 
         s.executeUpdate("INSERT INTO TestUpdateCharStream (c1, c2) " +
                 "VALUES ('AAAAA', 1)");
         s.executeUpdate("INSERT INTO TestUpdateCharStream (c1, c2) " +
@@ -3173,7 +3189,8 @@ public class parameterMapping {
         //update two rows and use large data
         //Once DERBY-6237 is fixed, we should remove following if condition
         if (!TestUtil.isEmbeddedFramework())
-        	helperTestDerby6237(2,2,conn);
+            helperTestDerby6237(2,2,conn);
+
         s.execute("DROP TABLE TestUpdateCharStream");
         s.close();
     }



Mime
View raw message