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 2006/03/15 14:11:19 UTC
svn commit: r386068 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java
Author: kahatlen
Date: Wed Mar 15 05:11:17 2006
New Revision: 386068
URL: http://svn.apache.org/viewcvs?rev=386068&view=rev
Log:
DERBY-992: A corner case bug and missing optimization in
ScrollInsensitiveResultSet
a) For a scrollable, insensitive result set (read-only) which is
empty, ResultSet#afterLast should have no effect, but erroneously
sets the internal variable afterLast to true, so that a subsequent
call to ResultSet#isAfterLast will return 'true' in the embedded
client. It does not happen on the client driver, because it seems
to do some double book-keeping for this case.
b) In ScrollInsensitiveResultSet#getNextRowCore and #getAbsoluteRow,
there are missing checks will cause unnecessary read (attempts)
from underlying result set even if end has been seen already.
Patch submitted by Dag H. Wanvik.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java?rev=386068&r1=386067&r2=386068&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java Wed Mar 15 05:11:17 2006
@@ -239,6 +239,10 @@
return null;
}
+ if (seenLast && row > lastPosition) {
+ return setAfterLastRow();
+ }
+
if (row > 0)
{
// position is from the start of the result set
@@ -423,6 +427,10 @@
if (!isOpen)
throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, "next");
+ if (seenLast && currentPosition == lastPosition) {
+ return setAfterLastRow();
+ }
+
/* Should we get the next row from the source or the hash table? */
if (currentPosition == positionInSource)
{
@@ -600,8 +608,15 @@
{
getLastRow();
}
- currentPosition = lastPosition + 1;
- afterLast = true;
+ if (lastPosition == 0) {
+ // empty rs special case
+ currentPosition = 0;
+ afterLast = false;
+ } else {
+ currentPosition = lastPosition + 1;
+ afterLast = true;
+ }
+
beforeFirst = false;
currentRow = null;
return null;
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java?rev=386068&r1=386067&r2=386068&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java Wed Mar 15 05:11:17 2006
@@ -823,6 +823,20 @@
rs.close();
+ // Empty result set tests (DERBY-992)
+ rs = s_i_r.executeQuery("select * from t where 1=0");
+ rs.afterLast();
+ if (rs.isAfterLast()) {
+ System.out.println("afterLast() on empty RS should be no-op");
+ }
+
+ rs.beforeFirst();
+ if (rs.isBeforeFirst()) {
+ System.out.println("beforeFirst() on empty RS should be no-op");
+ }
+
+ rs.close();
+
// Scroll insensitive and updatable
s_i_u = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);