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/14 11:46:35 UTC

svn commit: r414165 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ResultSet.java client/org/apache/derby/client/net/NetCursor.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java

Author: andreask
Date: Wed Jun 14 02:46:35 2006
New Revision: 414165

URL: http://svn.apache.org/viewvc?rev=414165&view=rev
Log:
DERBY-1382 lobs fail silently with result sets of type TYPE_SCROLL_INSENSITIVE in client jdbc driver. Contributed by Fernanda Pizzorno.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java?rev=414165&r1=414164&r2=414165&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java Wed Jun 14 02:46:35 2006
@@ -4836,6 +4836,8 @@
     }
 
     private void flowGetRowset(int orientation, long rowNumber) throws SqlException {
+        // clear lobs before fetching rows
+        cursor_.clearLobData_();
         cursor_.resetDataBuffer();
         agent_.beginWriteChain(statement_);
         

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java?rev=414165&r1=414164&r2=414165&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java Wed Jun 14 02:46:35 2006
@@ -128,10 +128,6 @@
         int colNullIndicator = CodePoint.NULLDATA;
         int length;
 
-        if (hasLobs_) {
-            extdtaPositions_.clear();  // reset positions for this row
-        }
-
         int[] columnDataPosition = null;
         int[] columnDataComputedLength = null;
         boolean[] columnDataIsNull = null;
@@ -141,6 +137,10 @@
         if ((position_ == lastValidBytePosition_) &&
                 (netResultSet_ != null) && (netResultSet_.scrollable_)) {
             return false;
+        }
+
+        if (hasLobs_) {
+            extdtaPositions_.clear();  // reset positions for this row
         }
 
         NetSqlca[] netSqlca = this.parseSQLCARD(qrydscTypdef_);

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=414165&r1=414164&r2=414165&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 Wed Jun 14 02:46:35 2006
@@ -50,6 +50,7 @@
 import org.apache.derby.tools.ij;
 import org.apache.derbyTesting.functionTests.util.Formatters;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
+import java.util.Arrays;
 
 /**
  * Test of JDBC blob and clob
@@ -183,6 +184,12 @@
   
            // restart the connection
             conn = ij.startJBMS();
+            
+            // do not run this test with DerbyNet
+            if (!TestUtil.isJCCFramework()) {
+                clobTest10(conn);
+            }
+  
             conn.setAutoCommit(false);
             clobTest96(conn);
 
@@ -210,6 +217,11 @@
             conn = ij.startJBMS();
             conn.setAutoCommit(false);
             blobTest96(conn);
+            
+            // do not run this test with DerbyNet
+            if (!TestUtil.isJCCFramework()) {
+                blobTest10(conn);
+            }
 
             clobTestSelfDestructive(conn);
             clobTestSelfDestructive2(conn);
@@ -2549,6 +2561,96 @@
 		}
     }
 
+
+    /**
+     * Test fix for derby-1382.
+     *
+     * Test that the getClob() returns the correct value for the clob before and
+     * after updating the clob when using result sets of type 
+     * TYPE_SCROLL_INSENSITIVE.
+     * 
+     * The method updateString(int, String) is used to set the value on the
+     * clob because the method updateBlob(int, Blob) has not yet been 
+     * implemented for DerbyNetClient.
+     *
+     * @param conn Connection
+     * @throws SQLException
+     */
+    private static void clobTest10(Connection conn) throws SQLException {
+        Statement s = conn.createStatement();
+        s.execute("CREATE TABLE derby1382 (c1 int, c2 clob)");
+
+        String clobData = "initial clob ";
+        PreparedStatement ps = 
+                conn.prepareStatement("insert into derby1382 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 derby1382");
+
+        String value;
+        Clob c;
+
+        rs.first();
+        checkContentsBeforeAndAfterUpdatingClob(rs);
+        rs.next();
+        checkContentsBeforeAndAfterUpdatingClob(rs);
+        rs.relative(3);
+        checkContentsBeforeAndAfterUpdatingClob(rs);
+        rs.absolute(7);
+        checkContentsBeforeAndAfterUpdatingClob(rs);
+        rs.previous();
+        checkContentsBeforeAndAfterUpdatingClob(rs);
+        rs.last();
+        checkContentsBeforeAndAfterUpdatingClob(rs);
+        rs.previous();
+        checkContentsBeforeAndAfterUpdatingClob(rs);
+
+        rs.close();
+        scrollStmt.close();
+
+        s.execute("DROP TABLE derby1382");
+        s.close();
+    }
+
+    private static void checkContentsBeforeAndAfterUpdatingClob(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("clobTest10 - Error: wrong clob value");
+        }
+        // update contents
+        value = updatedClobData + rs.getInt(1);
+        rs.updateString(2, value);
+        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("clobTest10 - Error: wrong clob value");
+        }
+    }
+
+
     // test behaviour of system with self destructive user
     // update a long column underneath a clob
 	private static void clobTestSelfDestructive(Connection conn)
@@ -4116,6 +4218,95 @@
 
     
     
+    /**
+     * Test fix for derby-1382.
+     *
+     * Test that the getBlob() returns the correct value for the blob before and
+     * after updating the blob when using result sets of type 
+     * TYPE_SCROLL_INSENSITIVE.
+     *
+     * The method updateBytes(int, byte[]) is used to set the value on the
+     * clob because the method updateClob(int, Clob) has not yet been 
+     * implemented for DerbyNetClient.
+
+     *
+     * @param conn Connection
+     * @throws SQLException
+     */
+    private static void blobTest10(Connection conn) throws SQLException {
+        Statement s = conn.createStatement();
+        s.execute("CREATE TABLE derby1382 (c1 int, c2 blob)");
+
+        String blobData = "initial blob ";
+        PreparedStatement ps = 
+                conn.prepareStatement("insert into derby1382 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 derby1382");
+
+        rs.first();
+        checkContentsBeforeAndAfterUpdatingBlob(rs);
+        rs.next();
+        checkContentsBeforeAndAfterUpdatingBlob(rs);
+        rs.relative(3);
+        checkContentsBeforeAndAfterUpdatingBlob(rs);
+        rs.absolute(7);
+        checkContentsBeforeAndAfterUpdatingBlob(rs);
+        rs.previous();
+        checkContentsBeforeAndAfterUpdatingBlob(rs);
+        rs.last();
+        checkContentsBeforeAndAfterUpdatingBlob(rs);
+        rs.previous();
+        checkContentsBeforeAndAfterUpdatingBlob(rs);
+
+        rs.close();
+        scrollStmt.close();
+
+        s.execute("DROP TABLE derby1382");
+        s.close();
+    }
+
+    private static void checkContentsBeforeAndAfterUpdatingBlob(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("blobTest10 - Error: wrong blob value");
+        }
+
+        // update contents
+        value = (updatedBlobData + rs.getInt(1)).getBytes();
+        rs.updateBytes(2, value);
+        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("blobTest10 - Error: wrong blob value");
+        }
+    }
+
+
     /**
      * Test fix for derby-265.
      * Test that if getBlob is called after the transaction