db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r208683 - in /incubator/derby/code/trunk/java: client/org/apache/derby/client/am/ engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/...
Date Thu, 30 Jun 2005 20:59:29 GMT
Author: djd
Date: Thu Jun 30 13:59:25 2005
New Revision: 208683

URL: http://svn.apache.org/viewcvs?rev=208683&view=rev
Log:
DERBY-276 The functionality of next,previous,first,last,beforeFirst,afterLast,relative and
absolute should be
aligned with ch. 14.2.2 in the JDBC 3.0 spec. Another issue found: absolute(0) should behave
like beforeFirst().

Patch contributed by Bernt Marius Johnsen - Bernt.Johnsen@Sun.COM


Modified:
    incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/scrollCursors1.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/scrollCursors1.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/scrollCursors1.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors1.sql
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java
    incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java

Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java?rev=208683&r1=208682&r2=208683&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java (original)
+++ incubator/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java Thu Jun
30 13:59:25 2005
@@ -1804,17 +1804,50 @@
         // discard all previous updates when moving the cursor.
         resetUpdatedColumns();
 
-        // this method may only be called when the cursor on a valid row,
-        // not after the last row, before the first row, or on the insert row.
-        // throw exception if result set contains no rows, because there is no current row.
-        if (isBeforeFirstX() || isAfterLastX() || isOnInsertRow_ || resultSetContainsNoRows())
{
+        // this method may not be called when the cursor on the insert row
+        if (isOnInsertRow_) {
             throw new SqlException(agent_.logWriter_, "Cursor is Not on a Valid Row");
         }
 
+        // If the resultset is empty, relative(n) is a null operation
+        if (resultSetContainsNoRows()) {
+            isValidCursorPosition_ = false;
+            return isValidCursorPosition_;
+        }
+        
+        // relative(0) is a null-operation, but the retruned result is
+        // dependent on wether the cursorposition is on a row or not.
         if (rows == 0) {
-            isValidCursorPosition_ = true;
+            if (isBeforeFirstX() || isAfterLastX()) {
+                isValidCursorPosition_ = false;
+            } else {
+                isValidCursorPosition_ = true;
+            }
             return isValidCursorPosition_;
         }
+
+        // Handle special cases when the cursor is before first or
+        // after last, since the following code assumes we ar on a
+        // valid cursor
+        if (isBeforeFirstX()) {
+            if (rows > 0) {
+                nextX();
+                return relativeX(rows-1);
+            } else {
+                isValidCursorPosition_ = false;
+                return isValidCursorPosition_;
+            }
+        }
+        if (isAfterLastX()) {
+            if (rows < 0) {
+                previousX();
+                return relativeX(rows+1);
+            } else {
+                isValidCursorPosition_ = false;
+                return isValidCursorPosition_;
+            }
+        }
+        // Ok, now we are on a row and ready to do some real positioning.....
 
         resetRowsetFlags();
 

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java?rev=208683&r1=208682&r2=208683&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
Thu Jun 30 13:59:25 2005
@@ -232,10 +232,11 @@
 			}
 		}
 
-		// 0 is an invalid parameter
+                // Absolute 0 is defined to be before first!
 		if (row == 0)
 		{
-			throw StandardException.newException(SQLState.LANG_ZERO_INVALID_FOR_R_S_ABSOLUTE);
+                    setBeforeFirstRow();
+                    return null;
 		}
 
 		if (row > 0)
@@ -330,16 +331,15 @@
 			}
 		}
 
-		/* Throw exception if before first or after last */
-		if (beforeFirst || afterLast)
-		{
-			throw StandardException.newException(SQLState.LANG_NO_CURRENT_ROW_FOR_RELATIVE);
-		}
-
 		// Return the current row for 0
 		if (row == 0)
 		{
+                    if ((beforeFirst || afterLast) ||
+                        (!beforeFirst && !afterLast)) {
+                        return null;
+                    } else {
 			return getRowFromHashTable(currentPosition);
+                    }
 		}
 		else if (row > 0)
 		{

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/scrollCursors1.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/scrollCursors1.out?rev=208683&r1=208682&r2=208683&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/scrollCursors1.out
(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/scrollCursors1.out
Thu Jun 30 13:59:25 2005
@@ -34,18 +34,15 @@
 IJ ERROR: RELATIVE is not allowed on a forward only cursor.
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- 0 is invalid value for absolute
-absolute 0 c1;
-IJ ERROR: 0 is an invalid value for ABSOLUTE <integer> <cursorname>
+ij> absolute 0 c1;
+No current row
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- relative is invalid when not positioned on a row
-relative 0 c1;
+ij> relative 0 c1;
 ERROR (no SQLState): Cursor is Not on a Valid Row
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- relative is invalid when not positioned on a row
-relative 2 c1;
+ij> relative 2 c1;
 ERROR (no SQLState): Cursor is Not on a Valid Row
 ij> close c1;
 ij> -- positive

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/scrollCursors1.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/scrollCursors1.out?rev=208683&r1=208682&r2=208683&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/scrollCursors1.out
(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/scrollCursors1.out
Thu Jun 30 13:59:25 2005
@@ -34,19 +34,18 @@
 IJ ERROR: RELATIVE is not allowed on a forward only cursor.
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- 0 is invalid value for absolute
-absolute 0 c1;
-IJ ERROR: 0 is an invalid value for ABSOLUTE <integer> <cursorname>
+ij> absolute 0 c1;
+No current row
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- relative is invalid when not positioned on a row
-relative 0 c1;
-ERROR (no SQLState): Cursor is Not on a Valid Row
+ij> relative 0 c1;
+No current row
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- relative is invalid when not positioned on a row
-relative 2 c1;
-ERROR (no SQLState): Cursor is Not on a Valid Row
+ij> relative 2 c1;
+C50 |I          
+-----
+c |3          
 ij> close c1;
 ij> -- positive
 ----- test positioning

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/scrollCursors1.out
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/scrollCursors1.out?rev=208683&r1=208682&r2=208683&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/scrollCursors1.out
(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/scrollCursors1.out
Thu Jun 30 13:59:25 2005
@@ -34,19 +34,18 @@
 IJ ERROR: RELATIVE is not allowed on a forward only cursor.
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- 0 is invalid value for absolute
-absolute 0 c1;
-IJ ERROR: 0 is an invalid value for ABSOLUTE <integer> <cursorname>
+ij> absolute 0 c1;
+No current row
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- relative is invalid when not positioned on a row
-relative 0 c1;
-ERROR X0X87: ResultSet.relative(int row) cannot be called when the cursor is not positioned
on a row.
+ij> relative 0 c1;
+No current row
 ij> close c1;
 ij> get scroll insensitive cursor c1 as 'select * from t1';
-ij> -- relative is invalid when not positioned on a row
-relative 2 c1;
-ERROR X0X87: ResultSet.relative(int row) cannot be called when the cursor is not positioned
on a row.
+ij> relative 2 c1;
+C50                                               |I          
+--------------------------------------------------------------
+c                                                 |3          
 ij> close c1;
 ij> -- positive
 -- test positioning

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors1.sql
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors1.sql?rev=208683&r1=208682&r2=208683&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors1.sql
(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors1.sql
Thu Jun 30 13:59:25 2005
@@ -25,18 +25,14 @@
 close c1;
 
 get scroll insensitive cursor c1 as 'select * from t1';
--- 0 is invalid value for absolute
 absolute 0 c1;
 close c1;
 get scroll insensitive cursor c1 as 'select * from t1';
--- relative is invalid when not positioned on a row
 relative 0 c1;
 close c1;
 get scroll insensitive cursor c1 as 'select * from t1';
--- relative is invalid when not positioned on a row
 relative 2 c1;
 close c1;
-
 
 -- positive
 

Modified: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java?rev=208683&r1=208682&r2=208683&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java
(original)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors2.java
Thu Jun 30 13:59:25 2005
@@ -613,6 +613,16 @@
 			System.out.println("expected to be before the 1st row");
 			passed = false;
 		}
+                if (rs.absolute(0))
+                {
+			System.out.println("absolute(0) expected to return false");
+			passed = false;
+                }
+		if (! rs.isBeforeFirst())
+		{
+			System.out.println("still expected to be before the 1st row");
+			passed = false;
+		}
 		// go to first row
 		if (! rs.first())
 		{
@@ -898,7 +908,6 @@
 			passed = false;
 		}
 		rs.close();
-		
 
 		return passed;
 	}
@@ -968,6 +977,11 @@
 			System.out.println("rs.next() expected to show result set is empty");
 			passed = false;
 		}
+		if (rs.previous())
+		{
+			System.out.println("rs.previous() expected to show result set is empty");
+			passed = false;
+		}
 		if (rs.isAfterLast())
 		{
 			System.out.println("isAfterLast() expected to return false on empty result set");
@@ -984,6 +998,42 @@
 			passed = false;
 		}
 
+		if (rs.relative(0))
+		{
+			System.out.println("relative(0) expected to return false on empty result set");
+			passed = false;
+		}
+
+		if (rs.relative(1))
+		{
+			System.out.println("relative(1) expected to return false on empty result set");
+			passed = false;
+		}
+
+		if (rs.relative(-1))
+		{
+			System.out.println("relative(-1) expected to return false on empty result set");
+			passed = false;
+		}
+
+		if (rs.absolute(0))
+		{
+			System.out.println("absolute(0) expected to return false on empty result set");
+			passed = false;
+		}
+		if (rs.absolute(1))
+		{
+			System.out.println("absolute(1) expected to return false on empty result set");
+			passed = false;
+		}
+
+		if (rs.absolute(-1))
+		{
+			System.out.println("absolute(-1) expected to return false on empty result set");
+			passed = false;
+		}
+
+
 		rs.close();
 		// End of empty result set tests
 
@@ -1000,19 +1050,6 @@
 		{
 			/* Check to be sure the exception is the one we expect */
 			passed = passed && checkException(sqle, "XJ062");
-		}
-
-		// absolute(0)
-		try
-		{
-			rs.absolute(0);
-			System.out.println("absolute(0) expected to fail");
-			passed = false;
-		}
-		catch (SQLException sqle)
-		{
-			/* Check to be sure the exception is the one we expect */
-			passed = passed && checkException(sqle, "X0X86");
 		}
 
 		s_i_r.close();

Modified: incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java?rev=208683&r1=208682&r2=208683&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java (original)
+++ incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java Thu
Jun 30 13:59:25 2005
@@ -693,12 +693,7 @@
 			throw ijException.forwardOnlyCursor("ABSOLUTE");
 		}
 
-		// 0 is an invalid value for row
-		if (row == 0)
-		{
-			throw ijException.zeroInvalidForAbsolute();
-		}
-
+		// 0 is an *VALID* value for row
 		return new ijRowResult(rs, rs.absolute(row));
 	}
 



Mime
View raw message