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 ka...@apache.org on 2014/09/23 10:28:48 UTC
svn commit: r1626964 - in /db/derby/code/branches/10.11: ./
java/client/org/apache/derby/client/am/ClientResultSet.java
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
Author: kahatlen
Date: Tue Sep 23 08:28:48 2014
New Revision: 1626964
URL: http://svn.apache.org/r1626964
Log:
DERBY-6737: CLOB retrieve exceptions after moving cursor around
Merged revision 1625904 from trunk.
Modified:
db/derby/code/branches/10.11/ (props changed)
db/derby/code/branches/10.11/java/client/org/apache/derby/client/am/ClientResultSet.java
db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
Propchange: db/derby/code/branches/10.11/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1625904
Modified: db/derby/code/branches/10.11/java/client/org/apache/derby/client/am/ClientResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/client/org/apache/derby/client/am/ClientResultSet.java?rev=1626964&r1=1626963&r2=1626964&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/client/org/apache/derby/client/am/ClientResultSet.java (original)
+++ db/derby/code/branches/10.11/java/client/org/apache/derby/client/am/ClientResultSet.java Tue Sep 23 08:28:48 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/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java?rev=1626964&r1=1626963&r2=1626964&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java (original)
+++ db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java Tue Sep 23 08:28:48 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();
+ }
}