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 an...@apache.org on 2006/06/30 11:59:00 UTC
svn commit: r418221 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java
Author: andreask
Date: Fri Jun 30 02:58:59 2006
New Revision: 418221
URL: http://svn.apache.org/viewvc?rev=418221&view=rev
Log:
DERBY-1421 updates of LOBs fails with scrollable updatable result sets. Contributed by Fernanda Pizzorno
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java?rev=418221&r1=418220&r2=418221&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java Fri Jun 30 02:58:59 2006
@@ -574,8 +574,8 @@
riChecker.doFKCheck(newBaseRow);
}
- rowChanger.updateRow(row,newBaseRow,baseRowLocation);
source.updateRow(newBaseRow);
+ rowChanger.updateRow(row,newBaseRow,baseRowLocation);
//beetle 3865, update cursor use index.
if (notifyCursor)
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java?rev=418221&r1=418220&r2=418221&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java Fri Jun 30 02:58:59 2006
@@ -33,6 +33,8 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
+import java.io.StringBufferInputStream;
+import java.io.StringReader;
import java.io.Writer;
import java.sql.Blob;
import java.sql.Clob;
@@ -185,9 +187,10 @@
// restart the connection
conn = ij.startJBMS();
- // do not run this test with DerbyNet
+ // do not run these tests with DerbyNet
if (!TestUtil.isJCCFramework()) {
clobTest10(conn);
+ clobTest14(conn);
}
conn.setAutoCommit(false);
@@ -218,9 +221,10 @@
conn.setAutoCommit(false);
blobTest96(conn);
- // do not run this test with DerbyNet
+ // do not run these tests with DerbyNet
if (!TestUtil.isJCCFramework()) {
blobTest10(conn);
+ blobTest11(conn);
}
clobTestSelfDestructive(conn);
@@ -2650,6 +2654,87 @@
}
}
+ /**
+ * Test fix for derby-1421.
+ *
+ * Test that the getClob() returns the correct value for the blob before and
+ * after updating the Clob using the method updateCharacterStream().
+ *
+ * @param conn Connection
+ * @throws SQLException
+ */
+ private static void clobTest14(Connection conn) throws SQLException {
+ Statement s = conn.createStatement();
+ s.execute("CREATE TABLE derby1421 (c1 int, c2 clob)");
+
+ String clobData = "initial clob ";
+ PreparedStatement ps =
+ conn.prepareStatement("insert into derby1421 values (?, ?)");
+ for (int i=0; i<10; i++) {
+ ps.setInt(1, i);
+ ps.setString(2, clobData + i);
+ ps.execute();
+ }
+ ps.close();
+
+ Statement scrollStmt = conn.createStatement(
+ ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs = scrollStmt.executeQuery("SELECT * FROM derby1421");
+
+ rs.first();
+ updateClobWithUpdateCharacterStream(rs);
+ rs.next();
+ updateClobWithUpdateCharacterStream(rs);
+ rs.relative(3);
+ updateClobWithUpdateCharacterStream(rs);
+ rs.absolute(7);
+ updateClobWithUpdateCharacterStream(rs);
+ rs.previous();
+ updateClobWithUpdateCharacterStream(rs);
+ rs.last();
+ updateClobWithUpdateCharacterStream(rs);
+ rs.previous();
+ updateClobWithUpdateCharacterStream(rs);
+
+ rs.close();
+ scrollStmt.close();
+
+ s.execute("DROP TABLE derby1421");
+ s.close();
+ }
+
+ private static void updateClobWithUpdateCharacterStream(ResultSet rs)
+ throws SQLException
+ {
+ Clob c;
+ String value, expectedValue;
+ String clobData = "initial clob ";
+ String updatedClobData = "updated clob ";
+
+ c = rs.getClob(2);
+ // check contents
+ value = c.getSubString(1, (int)c.length());
+ expectedValue = clobData + rs.getInt(1);
+ if (value.compareToIgnoreCase(expectedValue) != 0) {
+ System.out.println("clobTest14 - Error: wrong clob value");
+ }
+
+ // update contents
+ value = (updatedClobData + rs.getInt(1));
+ Reader updateValue = new StringReader(value);
+ rs.updateCharacterStream(2, updateValue, value.length());
+ rs.updateRow();
+ // check update values
+ rs.next(); // leave the row
+ rs.previous(); // go back to updated row
+ c = rs.getClob(2);
+ // check contents
+ value = c.getSubString(1, (int)c.length());
+ expectedValue = updatedClobData + rs.getInt(1);
+ if (value.compareToIgnoreCase(expectedValue) != 0) {
+ System.out.println("clobTest14 - Error: wrong clob value");
+ }
+ }
// test behaviour of system with self destructive user
// update a long column underneath a clob
@@ -4306,6 +4391,88 @@
}
}
+ /**
+ * Test fix for derby-1421.
+ *
+ * Test that the getBlob() returns the correct value for the blob before and
+ * after updating the blob using the method updateBinaryStream().
+ *
+ * @param conn Connection
+ * @throws SQLException
+ */
+ private static void blobTest11(Connection conn) throws SQLException {
+ Statement s = conn.createStatement();
+ s.execute("CREATE TABLE derby1421 (c1 int, c2 blob)");
+
+ String blobData = "initial blob ";
+ PreparedStatement ps =
+ conn.prepareStatement("insert into derby1421 values (?, ?)");
+ for (int i=0; i<10; i++) {
+ ps.setInt(1, i);
+ ps.setBytes(2, (blobData + i).getBytes());
+ ps.execute();
+ }
+ ps.close();
+
+ Statement scrollStmt = conn.createStatement(
+ ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs = scrollStmt.executeQuery("SELECT * FROM derby1421");
+
+ rs.first();
+ updateBlobWithUpdateBinaryStream(rs);
+ rs.next();
+ updateBlobWithUpdateBinaryStream(rs);
+ rs.relative(3);
+ updateBlobWithUpdateBinaryStream(rs);
+ rs.absolute(7);
+ updateBlobWithUpdateBinaryStream(rs);
+ rs.previous();
+ updateBlobWithUpdateBinaryStream(rs);
+ rs.last();
+ updateBlobWithUpdateBinaryStream(rs);
+ rs.previous();
+ updateBlobWithUpdateBinaryStream(rs);
+
+ rs.close();
+ scrollStmt.close();
+
+ s.execute("DROP TABLE derby1421");
+ s.close();
+ }
+
+ private static void updateBlobWithUpdateBinaryStream(ResultSet rs)
+ throws SQLException
+ {
+ Blob b;
+ byte[] value, expectedValue;
+ String blobData = "initial blob ";
+ String updatedBlobData = "updated blob ";
+
+ b = rs.getBlob(2);
+ // check contents
+ value = b.getBytes(1, blobData.length() + 1);
+ expectedValue = (blobData + rs.getInt(1)).getBytes();
+ if (!Arrays.equals(value, expectedValue)) {
+ System.out.println("blobTest11 - Error: wrong blob value");
+ }
+
+ // update contents
+ value = (updatedBlobData + rs.getInt(1)).getBytes();
+ InputStream updateValue = new ByteArrayInputStream(value);
+ rs.updateBinaryStream(2, updateValue, value.length);
+ rs.updateRow();
+ // check update values
+ rs.next(); // leave the row
+ rs.previous(); // go back to updated row
+ b = rs.getBlob(2);
+ // check contents
+ value = b.getBytes(1, updatedBlobData.length() + 1);
+ expectedValue = (updatedBlobData + rs.getInt(1)).getBytes();
+ if (!Arrays.equals(value, expectedValue))
+ {
+ System.out.println("blobTest11 - Error: wrong blob value");
+ }
+ }
/**
* Test fix for derby-265.