db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1625904 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ClientResultSet.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
Date Thu, 18 Sep 2014 07:36:10 GMT
Author: kahatlen
Date: Thu Sep 18 07:36:10 2014
New Revision: 1625904

URL: http://svn.apache.org/r1625904
Log:
DERBY-6737: CLOB retrieve exceptions after moving cursor around

Always fetch the row again from the server when moving the position of
a scrollable result set that contains LOB columns.

Without this fix, if one of the absolute positioning methods is used
(first(), last() or absolute(int)), and the old position is the same
as the new position, the result set will use the values it already has
for the row on that position. Any locators will have been released,
though, so accessing LOBs in the row will fail with 'invalid locator'.

By fetching the row again from the server, we get a fresh and valid
locator for the LOB columns in that row.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java?rev=1625904&r1=1625903&r2=1625904&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java Thu Sep
18 07:36:10 2014
@@ -4839,6 +4839,11 @@ public abstract class ClientResultSet im
             default:
                 return false;
             }
+        } else if (resultSetMetaData_.hasLobColumns()) {
+            // DERBY-6737: If the result set has LOB columns, we cannot use
+            // the cached locator since it might have been released, so
+            // always fetch the row from the server.
+            return false;
         } else {
             return rowIsInCurrentRowset(rowNumber);
         }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java?rev=1625904&r1=1625903&r2=1625904&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
Thu Sep 18 07:36:10 2014
@@ -20,6 +20,7 @@
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -36,13 +37,16 @@ import org.apache.derbyTesting.junit.Tes
  *
  * Tests:
  * - testNextOnLastRowForwardOnly: tests that the result set is closed when all
- * rows have been retreived and next has been called from the last row, 
+ * rows have been retrieved and next has been called from the last row,
  * autocommit = true, the result set is not holdable and type forward 
  * only. (DERBY-1295)
  * - testNextOnLastRowScrollable: tests that the result set is not closed when 
  * next is called while the result set is positioned in the last row, 
  * autocommit = true, the result set is not holdable type scrollable 
  * insensitive. (DERBY-1295)
+ * - testDerby6737: tests that a LOB can be accessed after using an absolute
+ * positioning method to move the position to the row on which the result set
+ * is currently positioned. (DERBY-6737)
  *
  */
 public class ScrollResultSetTest extends BaseJDBCTestCase {
@@ -157,5 +161,73 @@ public class ScrollResultSetTest extends
         rs.close();
 
     }
-       
+
+    /**
+     * <p>
+     * Test that it is possible to access LOBs after moving the position of
+     * a scrollable result set from one row to the same row. Before DERBY-6737
+     * the following sequence of calls
+     * </p>
+     *
+     * <pre>
+     * rs.last();
+     * rs.first();
+     * rs.getClob(1).length();
+     * </pre>
+     *
+     * <p>
+     * would fail with 'invalid locator' on the client, if the result set
+     * contained only one row.
+     * </p>
+     */
+    public void testDerby6737() throws SQLException {
+        Statement s = createStatement();
+        s.execute("create table d6737(c clob)");
+        s.execute("insert into d6737 values 'abc'");
+
+        PreparedStatement ps = prepareStatement("select * from d6737",
+                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+
+        ResultSet rs = ps.executeQuery();
+        assertTrue(rs.last());
+        assertTrue(rs.first());
+        assertEquals(3, rs.getClob(1).length()); // used to fail on client
+        rs.close();
+
+        rs = ps.executeQuery();
+        assertTrue(rs.next());
+        assertTrue(rs.first());
+        assertEquals(3, rs.getClob(1).length()); // used to fail on client
+        rs.close();
+
+        rs = ps.executeQuery();
+        assertTrue(rs.first());
+        assertTrue(rs.last());
+        assertEquals(3, rs.getClob(1).length()); // used to fail on client
+        rs.close();
+
+        rs = ps.executeQuery();
+        assertTrue(rs.last());
+        assertTrue(rs.absolute(1));
+        assertEquals(3, rs.getClob(1).length()); // used to fail on client
+        rs.close();
+
+        // This case, where the CLOB had been accessed, but not explicitly
+        // freed before the result set was repositioned, passed even before
+        // the fix.
+        rs = ps.executeQuery();
+        assertTrue(rs.last());
+        assertEquals(3, rs.getClob(1).length());
+        assertTrue(rs.first());
+        assertEquals(3, rs.getClob(1).length());
+        rs.close();
+
+        // But it failed if the CLOB was explicitly freed before repositioning.
+        rs = ps.executeQuery();
+        assertTrue(rs.last());
+        rs.getClob(1).free();
+        assertTrue(rs.first());
+        assertEquals(3, rs.getClob(1).length()); // used to fail on client
+        rs.close();
+    }
 }



Mime
View raw message