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 be...@apache.org on 2006/05/23 13:43:32 UTC

svn commit: r408875 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing...

Author: bernt
Date: Tue May 23 04:43:31 2006
New Revision: 408875

URL: http://svn.apache.org/viewvc?rev=408875&view=rev
Log:
DERBY-1323 Detectability methods rowUpdated, rowInserted, rowDeleted can be called from illegal states in both clients. Submitted by Dag H. Wanvik

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/updatableResultSet.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/updatableResultSet.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/updatableResultSet.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_foundation/updatableResultSet.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk14/updatableResultSet.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/updatableResultSet.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.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=408875&r1=408874&r2=408875&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 Tue May 23 04:43:31 2006
@@ -2725,6 +2725,7 @@
         try
         {
             checkForClosedResultSet();
+            checkPositionedOnPlainRow();
 
             boolean rowUpdated = cursor_.getIsRowUpdated();
 
@@ -2742,8 +2743,14 @@
     public boolean rowInserted() throws SQLException {
         try
         {
-            boolean rowInserted = false;
             checkForClosedResultSet();
+            checkPositionedOnPlainRow();
+
+            boolean rowInserted = false;
+
+            // Not implemented for any result set type,
+            // so it always returns false.
+
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceExit(this, "rowInserted", rowInserted);
             }
@@ -2759,10 +2766,11 @@
         try
         {
             checkForClosedResultSet();
+            checkPositionedOnPlainRow();
 
-            boolean rowDeleted = (resultSetType_ == ResultSet.TYPE_SCROLL_INSENSITIVE) ?
-		cursor_.getIsUpdateDeleteHole() :
-		false;
+            boolean rowDeleted = 
+                (resultSetType_ == ResultSet.TYPE_SCROLL_INSENSITIVE) ?
+                cursor_.getIsUpdateDeleteHole() : false;
 
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceExit(this, "rowDeleted", rowDeleted);
@@ -4619,6 +4627,16 @@
                 new ClientMessageId(SQLState.CURSOR_INVALID_OPERATION_AT_CURRENT_POSITION));
         }
     }
+
+
+    private final void checkPositionedOnPlainRow() throws SqlException {
+        if (isOnInsertRow_ || !isValidCursorPosition_) {
+            throw new SqlException
+                (agent_.logWriter_, 
+                 new ClientMessageId(SQLState.NO_CURRENT_ROW));
+        }
+    }
+
 
     private final void checkThatResultSetTypeIsScrollable() throws SqlException {
         if (resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY) {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Tue May 23 04:43:31 2006
@@ -2155,6 +2155,9 @@
 	 */
 	public boolean rowUpdated() throws SQLException {
 		checkIfClosed("rowUpdated");
+		checkNotOnInsertRow();
+		checkOnRow();
+
         boolean rvalue = false;
 
 		try {
@@ -2182,6 +2185,9 @@
 	 */
 	public boolean rowInserted() throws SQLException {
 		checkIfClosed("rowInserted");
+		checkNotOnInsertRow();
+		checkOnRow();
+
 		return false;
 	}
 
@@ -2201,6 +2207,9 @@
 	 */
 	public boolean rowDeleted() throws SQLException {
 		checkIfClosed("rowUpdated");
+		checkNotOnInsertRow();
+		checkOnRow();
+
         boolean rvalue = false;
 
 		try {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/updatableResultSet.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/updatableResultSet.out?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/updatableResultSet.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/updatableResultSet.out Tue May 23 04:43:31 2006
@@ -222,7 +222,6 @@
 The JDBC program should look at rowDeleted only if deletesAreDetected returns true
 Since Derby returns false for detlesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowDeleted() for FORWARD_ONLY updatable resultsets
 Have this call to rs.rowDeleted() just to make sure the method does always return false? false
-Have this call to rs.rowDeleted() just to make sure the method does always return false? false
 Positive Test6b - For Forward Only resultsets, DatabaseMetaData will return false for ownUpdatesAreVisible and updatesAreDetected
 This is because, after updateRow, we position the ResultSet before the next row
 ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? false
@@ -230,7 +229,6 @@
 updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? false
 The JDBC program should look at rowUpdated only if updatesAreDetected returns true
 Since Derby returns false for updatesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowUpdated() for FORWARD_ONLY updatable resultsets
-Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Positive Test7a - delete using updatable resultset api from a temporary table
 following rows in temp table before deleteRow

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/updatableResultSet.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/updatableResultSet.out?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/updatableResultSet.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/updatableResultSet.out Tue May 23 04:43:31 2006
@@ -222,7 +222,6 @@
 The JDBC program should look at rowDeleted only if deletesAreDetected returns true
 Since Derby returns false for detlesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowDeleted() for FORWARD_ONLY updatable resultsets
 Have this call to rs.rowDeleted() just to make sure the method does always return false? false
-Have this call to rs.rowDeleted() just to make sure the method does always return false? false
 Positive Test6b - For Forward Only resultsets, DatabaseMetaData will return false for ownUpdatesAreVisible and updatesAreDetected
 This is because, after updateRow, we position the ResultSet before the next row
 ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? false
@@ -230,7 +229,6 @@
 updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? false
 The JDBC program should look at rowUpdated only if updatesAreDetected returns true
 Since Derby returns false for updatesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowUpdated() for FORWARD_ONLY updatable resultsets
-Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Positive Test7a - delete using updatable resultset api from a temporary table
 following rows in temp table before deleteRow

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/updatableResultSet.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/updatableResultSet.out?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/updatableResultSet.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/updatableResultSet.out Tue May 23 04:43:31 2006
@@ -216,7 +216,6 @@
 The JDBC program should look at rowDeleted only if deletesAreDetected returns true
 Since Derby returns false for detlesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowDeleted() for FORWARD_ONLY updatable resultsets
 Have this call to rs.rowDeleted() just to make sure the method does always return false? false
-Have this call to rs.rowDeleted() just to make sure the method does always return false? false
 Positive Test6b - For Forward Only resultsets, DatabaseMetaData will return false for ownUpdatesAreVisible and updatesAreDetected
 This is because, after updateRow, we position the ResultSet before the next row
 ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? false
@@ -224,7 +223,6 @@
 updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? false
 The JDBC program should look at rowUpdated only if updatesAreDetected returns true
 Since Derby returns false for updatesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowUpdated() for FORWARD_ONLY updatable resultsets
-Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Positive Test7a - delete using updatable resultset api from a temporary table
 following rows in temp table before deleteRow

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_foundation/updatableResultSet.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_foundation/updatableResultSet.out?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_foundation/updatableResultSet.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_foundation/updatableResultSet.out Tue May 23 04:43:31 2006
@@ -221,7 +221,6 @@
 The JDBC program should look at rowDeleted only if deletesAreDetected returns true
 Since Derby returns false for detlesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowDeleted() for FORWARD_ONLY updatable resultsets
 Have this call to rs.rowDeleted() just to make sure the method does always return false? false
-Have this call to rs.rowDeleted() just to make sure the method does always return false? false
 Positive Test6b - For Forward Only resultsets, DatabaseMetaData will return false for ownUpdatesAreVisible and updatesAreDetected
 This is because, after updateRow, we position the ResultSet before the next row
 ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? false
@@ -229,7 +228,6 @@
 updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? false
 The JDBC program should look at rowUpdated only if updatesAreDetected returns true
 Since Derby returns false for updatesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowUpdated() for FORWARD_ONLY updatable resultsets
-Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Positive Test7a - delete using updatable resultset api from a temporary table
 following rows in temp table before deleteRow

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk14/updatableResultSet.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk14/updatableResultSet.out?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk14/updatableResultSet.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk14/updatableResultSet.out Tue May 23 04:43:31 2006
@@ -221,7 +221,6 @@
 The JDBC program should look at rowDeleted only if deletesAreDetected returns true
 Since Derby returns false for detlesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowDeleted() for FORWARD_ONLY updatable resultsets
 Have this call to rs.rowDeleted() just to make sure the method does always return false? false
-Have this call to rs.rowDeleted() just to make sure the method does always return false? false
 Positive Test6b - For Forward Only resultsets, DatabaseMetaData will return false for ownUpdatesAreVisible and updatesAreDetected
 This is because, after updateRow, we position the ResultSet before the next row
 ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? false
@@ -229,7 +228,6 @@
 updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? false
 The JDBC program should look at rowUpdated only if updatesAreDetected returns true
 Since Derby returns false for updatesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowUpdated() for FORWARD_ONLY updatable resultsets
-Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Positive Test7a - delete using updatable resultset api from a temporary table
 following rows in temp table before deleteRow

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/updatableResultSet.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/updatableResultSet.out?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/updatableResultSet.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/updatableResultSet.out Tue May 23 04:43:31 2006
@@ -221,7 +221,6 @@
 The JDBC program should look at rowDeleted only if deletesAreDetected returns true
 Since Derby returns false for detlesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowDeleted() for FORWARD_ONLY updatable resultsets
 Have this call to rs.rowDeleted() just to make sure the method does always return false? false
-Have this call to rs.rowDeleted() just to make sure the method does always return false? false
 Positive Test6b - For Forward Only resultsets, DatabaseMetaData will return false for ownUpdatesAreVisible and updatesAreDetected
 This is because, after updateRow, we position the ResultSet before the next row
 ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)? false
@@ -229,7 +228,6 @@
 updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)? false
 The JDBC program should look at rowUpdated only if updatesAreDetected returns true
 Since Derby returns false for updatesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowUpdated() for FORWARD_ONLY updatable resultsets
-Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Have this call to rs.rowUpdated() just to make sure the method does always return false? false
 Positive Test7a - delete using updatable resultset api from a temporary table
 following rows in temp table before deleteRow

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java Tue May 23 04:43:31 2006
@@ -27,6 +27,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import java.util.Iterator;
+
 /**
  * Tests for variants of scrollable updatable resultsets.
  *
@@ -1061,6 +1062,120 @@
         testScrollInsensistiveConurUpdatable3(rs);
     }
     
+    /**
+     * Check that detectability methods throw the correct exception
+     * when called in an illegal row state, that is, somehow not
+     * positioned on a row. Minion of testDetectabilityExceptions.
+     *
+     * @param rs An open updatable result set.
+     * @param state A string describing the illegal state.
+     * @return No return value.
+     */
+    private void checkDetectabilityCallsOutsideRow(ResultSet rs, 
+                                                   String state)
+    {
+        boolean b;
+        
+        try {
+            b = rs.rowUpdated();
+            fail("rowUpdated while " + state + 
+                 " did not throw exception: " + b);
+        } catch (SQLException e) {
+            assertEquals(e.getSQLState(),
+                         INVALID_CURSOR_STATE_NO_CURRENT_ROW);
+        }
+
+        try {
+            b = rs.rowDeleted();
+            fail("rowdeleted while " + state + 
+                 " did not throw exception: " + b);
+        } catch (SQLException e) {
+            assertEquals(e.getSQLState(),
+                         INVALID_CURSOR_STATE_NO_CURRENT_ROW);
+        }
+
+        try {
+            b = rs.rowInserted();
+            fail("rowInserted while " + state + 
+                 " did not throw exception: " + b);
+        } catch (SQLException e) {
+            assertEquals(e.getSQLState(),
+                         INVALID_CURSOR_STATE_NO_CURRENT_ROW);
+        }
+    }
+
+
+    /**
+     * Test that the JDBC detectability calls throw correct exceptions when
+     * called in in wrong row states. 
+     * This is done for both supported updatable result set types.
+     */
+    public void testDetectabilityExceptions() throws SQLException 
+    {
+        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+                                          ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery("select * from t1");
+        
+        checkDetectabilityCallsOutsideRow(rs, "before positioning");
+
+        rs.moveToInsertRow();
+        checkDetectabilityCallsOutsideRow(rs, 
+                                          "on insertRow before positioning");
+
+        rs.next();
+        rs.moveToInsertRow();
+        checkDetectabilityCallsOutsideRow(rs, "on insertRow");
+        rs.moveToCurrentRow(); // needed until to DERBY-1322 is fixed
+
+        rs.beforeFirst();
+        checkDetectabilityCallsOutsideRow(rs, "on beforeFirst row");
+
+        rs.afterLast();
+        checkDetectabilityCallsOutsideRow(rs, "on afterLast row");
+
+        rs.first();
+        rs.deleteRow();
+        checkDetectabilityCallsOutsideRow(rs, "after deleteRow");
+
+        rs.last();
+        rs.deleteRow();
+        checkDetectabilityCallsOutsideRow(rs, "after deleteRow of last row");
+
+        rs.close();
+        s.close();
+
+        // Not strictly SUR, but fixed in same patch, so we test it here.
+        s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                                ResultSet.CONCUR_UPDATABLE);
+        rs = s.executeQuery("select * from t1");
+
+        checkDetectabilityCallsOutsideRow(rs, "before FO positioning");
+
+        rs.moveToInsertRow();
+        checkDetectabilityCallsOutsideRow(rs, 
+                                          "on insertRow before FO positioning");
+
+        rs.next();
+        rs.moveToInsertRow();
+        checkDetectabilityCallsOutsideRow(rs, "on FO insertRow");
+
+        rs.next();
+        rs.updateInt(2, 666);
+        rs.updateRow();
+        checkDetectabilityCallsOutsideRow(rs, "after FO updateRow");
+
+        rs.next();
+        rs.deleteRow();
+        checkDetectabilityCallsOutsideRow(rs, "after FO deleteRow");
+
+        while (rs.next()) {};
+        checkDetectabilityCallsOutsideRow(rs, "after FO emptied out");
+
+        rs.close();
+        s.close();
+    }
+
+
     /**
      * Get a cursor name. We use the same cursor name for all cursors.
      */

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java?rev=408875&r1=408874&r2=408875&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java Tue May 23 04:43:31 2006
@@ -971,7 +971,6 @@
       System.out.println("Since Derby returns false for detlesAreDetected for FORWARD_ONLY updatable resultset,the program should not rely on rs.rowDeleted() for FORWARD_ONLY updatable resultsets");
       System.out.println("Have this call to rs.rowDeleted() just to make sure the method does always return false? " + rs.rowDeleted());
 			rs.deleteRow();
-      System.out.println("Have this call to rs.rowDeleted() just to make sure the method does always return false? " + rs.rowDeleted());
 			rs.close();
 
 			System.out.println("Positive Test6b - For Forward Only resultsets, DatabaseMetaData will return false for ownUpdatesAreVisible and updatesAreDetected");
@@ -989,7 +988,6 @@
 			System.out.println("Have this call to rs.rowUpdated() just to make sure the method does always return false? " + rs.rowUpdated());
 			rs.updateLong(1,123);
 			rs.updateRow();
-			System.out.println("Have this call to rs.rowUpdated() just to make sure the method does always return false? " + rs.rowUpdated());
 			rs.close();
 
 			System.out.println("Positive Test7a - delete using updatable resultset api from a temporary table");