You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ma...@apache.org on 2013/06/01 23:25:25 UTC
svn commit: r1488606 -
/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/parameterMapping.java
Author: mamta
Date: Sat Jun 1 21:25:25 2013
New Revision: 1488606
URL: http://svn.apache.org/r1488606
Log:
DERBY-6237(PreparedStatement.execute() fails starting 10.2 when multiple rows are updated and PreparedStatement.setCharacterStream(int, Reader, int) is used)
This commit separates testing of setCharacterStream on CLOB and VARCHAR columns as 2 separate tests. This way failure of one data type will not mask the behavior of the other data type.
I found through this test sparation that in 10.2,
1)setCharacterStream on VARCHAR columns work fine(just like 10.1 release) for both one row and multi-row update through prepared statement.
2)But setCharacterStream on CLOB column when update touches more than one row(in case of embedded only) fails in 10.2 release.
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=1488606&r1=1488605&r2=1488606&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 21:25:25 2013
@@ -306,7 +306,10 @@ public class parameterMapping {
// make the initial connection.
ij.getPropertyArg(args);
Connection conn = ij.startJBMS();
- testDERBY6237(conn);
+ //test setCharacterStream on CLOB
+ testDERBY6237(conn,true);
+ //test setCharacterStream on VARCHAR
+ testDERBY6237(conn,false);
conn.setAutoCommit(false);
@@ -3048,53 +3051,66 @@ public class parameterMapping {
//numberOfRowsToUpdate - value 1 or 2
//testVariation - if 1 then update CLOB with short data
// if 2 then update CLOB with large data
+ //testCLOB - true means test setCharacterStream on CLOB
+ // - false means test setCharacterStream on VARCHAR
private static void helperTestDerby6237(int numberOfRowsToUpdate,
int testVariation,
- Connection conn) throws Exception
+ Connection conn,
+ boolean testCLOB) throws Exception
{
CharAlphabet a1 = CharAlphabet.singleChar('a');
//Following will update one or 2 rows depending on the 1st param
+ //Following will update CLOB column or VARCHAR column with short
+ // or large data depending on param 2
+ //Following will update CLOB column or VARCHAR column depending
+ // on 3rd param
PreparedStatement ps = conn.prepareStatement(
- "UPDATE TestUpdateCharStream SET c3 = ?, c4 = ?, " +
+ "UPDATE TestUpdateCharStream SET " +
+ (testCLOB==true ? "c3" : "c4") + " = ?, " +
"c2 = c2 + 1 WHERE c1 IN (?, ?)");
-
switch (testVariation) {
case 1 :
//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);
+ if (testCLOB) {
+ //for CLOB column, use 50K data
+ ps.setCharacterStream(1,
+ new LoopingAlphabetReader(50000, a1), 50000);
+ } else {
+ //for VARCHAR column, use 32K data
+ ps.setCharacterStream(1,
+ 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(3, new CharArrayReader("AAAAA".toCharArray()), 5);
+ ps.setCharacterStream(2, 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(4, "AAAAA", Types.VARCHAR);
+ ps.setObject(3, "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(4, "EEEEE", Types.VARCHAR);
+ ps.setObject(3, "EEEEE", Types.VARCHAR);
}
ps.execute();
- //verify updated data
+ //verify updated data. Update happened to either CLOB column or VARCHAR
+ // column. It is decided by param 3
ResultSet rs;
ps = conn.prepareStatement(
- "select c3, c4 from TestUpdateCharStream " +
+ "select " +
+ (testCLOB==true ? "c3 " : "c4 ") +
+ "from TestUpdateCharStream " +
"WHERE c1 IN (?, ?)");
ps.setCharacterStream(1, new CharArrayReader("AAAAA".toCharArray()), 5);
if (numberOfRowsToUpdate == 1 ) {
@@ -3103,30 +3119,23 @@ public class parameterMapping {
ps.setObject(2, "EEEEE", Types.VARCHAR);
}
rs = ps.executeQuery();
- char[] c, c1;
+ char[] c;
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');
+ if (testCLOB)
+ c = new char[50000];
+ else
+ c = new char[32000];
}
+ Arrays.fill(c, 'a');
for (int i=0;i<numberOfRowsToUpdate;i++) {
rs.next();
if (!compareClobReader2CharArray(c,rs.getCharacterStream(1))) {
- 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");
+ System.out.println("FAIL: " +
+ (testCLOB ? "CLOB " : "VARCHAR ") + "data should have matched");
rs.close();
ps.close();
return;
@@ -3163,9 +3172,14 @@ public class parameterMapping {
* PreparedStatement.setCharacterStream(int, Reader, int) is used)
* In 10.1, setCharacterStream to update CLOB and varchar columns
* work even when update is going to update more than one row
+ *
+ * @param conn - Connection object
+ * @param testCLOB - true means test setCharacterStream on CLOB
+ * - false means test setCharacterStream on VARCHAR
* @throws Exception
*/
- private static void testDERBY6237(Connection conn) throws Exception
+ private static void testDERBY6237(Connection conn,
+ boolean testCLOB) throws Exception
{
Statement s = conn.createStatement();
s.executeUpdate("CREATE TABLE TestUpdateCharStream ("+
@@ -3179,17 +3193,19 @@ public class parameterMapping {
"VALUES ('EEEEE', 1)");
//update only one row and use short data
- helperTestDerby6237(1,1,conn);
+ helperTestDerby6237(1,1,conn, testCLOB);
//update only one row and use large data
- helperTestDerby6237(1,2,conn);
+ helperTestDerby6237(1,2,conn, testCLOB);
//update two rows and use short data
//Once DERBY-6237 is fixed, we should remove following if condition
- if (!TestUtil.isEmbeddedFramework())
- helperTestDerby6237(2,1,conn);
+ if (!(testCLOB && TestUtil.isEmbeddedFramework()))
+ helperTestDerby6237(2,1,conn, testCLOB);
//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);
+ // Following if condition will skip the test for 2 row update when
+ // testing CLOB columns. This results in failure in 10.2
+ if (!(testCLOB && TestUtil.isEmbeddedFramework()))
+ helperTestDerby6237(2,2,conn, testCLOB);
s.execute("DROP TABLE TestUpdateCharStream");
s.close();