db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From be...@apache.org
Subject svn commit: r409170 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ResultSet.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java
Date Wed, 24 May 2006 14:09:05 GMT
Author: bernt
Date: Wed May 24 07:09:04 2006
New Revision: 409170

URL: http://svn.apache.org/viewvc?rev=409170&view=rev
Log:
DERBY-1322: Missing resets of isOnInsertRow state in net client when navigating away via other
than ResultSet#next. Submitted by Fernanda Pizzorno

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.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=409170&r1=409169&r2=409170&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 Wed May 24 07:09:04
2006
@@ -281,10 +281,7 @@
         checkForClosedResultSet();
         clearWarningsX();
 
-        if (isOnInsertRow_) {
-            isOnInsertRow_ = false;
-            isOnCurrentRow_ = true;
-        }
+        moveToCurrentRowX();
         
         wasNull_ = ResultSet.WAS_NULL_UNSET;
 
@@ -2111,6 +2108,8 @@
 	resetRowsetFlags();
 	unuseStreams();
 
+        moveToCurrentRowX();
+
         // this method has no effect if the result set has no rows.
         // only send cntqry to position the cursor before first if
         // resultset contains rows and it is not already before first, or
@@ -2148,6 +2147,8 @@
     private void afterLastX() throws SqlException {
         resetRowsetFlags();
     unuseStreams();
+    
+        moveToCurrentRowX();
 
         // this method has no effect if the result set has no rows.
         // only send cntqry to position the cursor after last if
@@ -2188,6 +2189,8 @@
         checkForClosedResultSet();
         checkThatResultSetTypeIsScrollable();
         clearWarningsX();
+        
+        moveToCurrentRowX();
 
         wasNull_ = ResultSet.WAS_NULL_UNSET;
 
@@ -2241,6 +2244,8 @@
         checkForClosedResultSet();
         checkThatResultSetTypeIsScrollable();
         clearWarningsX();
+        
+        moveToCurrentRowX();
 
         wasNull_ = ResultSet.WAS_NULL_UNSET;
 
@@ -2357,6 +2362,8 @@
         checkThatResultSetTypeIsScrollable();
         clearWarningsX();
 
+        moveToCurrentRowX();
+
         wasNull_ = ResultSet.WAS_NULL_UNSET;
 
         // discard all previous updates when moving the cursor.
@@ -2439,6 +2446,9 @@
         checkForClosedResultSet();
         checkThatResultSetTypeIsScrollable();
         clearWarningsX();
+        
+        moveToCurrentRowX();
+        
         wasNull_ = ResultSet.WAS_NULL_UNSET;
 
         // discard all previous updates when moving the cursor.
@@ -2446,12 +2456,6 @@
 	
 	unuseStreams();
 
-        // this method may not be called when the cursor on the insert row
-        if (isOnInsertRow_) {
-            throw new SqlException(agent_.logWriter_, 
-                new ClientMessageId(SQLState.CURSOR_INVALID_OPERATION_AT_CURRENT_POSITION));
-        }
-
         // If the resultset is empty, relative(n) is a null operation
         if (resultSetContainsNoRows()) {
             isValidCursorPosition_ = false;
@@ -2569,6 +2573,8 @@
         checkForClosedResultSet();
         checkThatResultSetTypeIsScrollable();
         clearWarningsX();
+        
+        moveToCurrentRowX();
 
         wasNull_ = ResultSet.WAS_NULL_UNSET;
 
@@ -3741,22 +3747,24 @@
                 checkForClosedResultSet();
                 checkForUpdatableResultSet("moveToCurrentRow");
 
-                if (!isOnInsertRow_) {
-                    // no affect
-                } else {
-                    resetUpdatedColumns();
-                    isOnInsertRow_ = false;
-                    isOnCurrentRow_ = true;
-                    if (currentRowInRowset_ > 0) {
-                        updateColumnInfoFromCache();
-                    }
-                    isValidCursorPosition_ = true;
-                }
+                moveToCurrentRowX();
             }
         }
         catch ( SqlException se )
         {
             throw se.getSQLException();
+        }
+    }
+    
+    private void moveToCurrentRowX() throws SqlException {
+        if (isOnInsertRow_) {
+            resetUpdatedColumns();
+            isOnInsertRow_ = false;
+            isOnCurrentRow_ = true;
+            if (currentRowInRowset_ > 0) {
+                updateColumnInfoFromCache();
+            }
+            isValidCursorPosition_ = true;
         }
     }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java?rev=409170&r1=409169&r2=409170&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
Wed May 24 07:09:04 2006
@@ -304,4 +304,5 @@
     final static String INVALID_CURSOR_STATE_NO_CURRENT_ROW = "24000";
     final static String CURSOR_OPERATION_CONFLICT = "01001";
     final static String QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET = "01J06";
+    final static String CURSOR_NOT_POSITIONED_ON_INSERT_ROW = "XJ086";
 }

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=409170&r1=409169&r2=409170&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
Wed May 24 07:09:04 2006
@@ -494,6 +494,158 @@
     }
     
     /**
+     * Tests that it is possible to move using positioning methods after
+     * moveToInsertRow and that it is possible to delete a row after 
+     * positioning back from insertRow. Also tests that it is possible to 
+     * insert a row when positioned on insert row, that it is not possible
+     * to update or delete a row from insertRow and that it also is not possible
+     * to insert a row without being on insert row.
+     */
+    public void testInsertRowWithScrollCursor() throws SQLException {
+        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+                                          ResultSet.CONCUR_UPDATABLE);
+        
+        int currentPosition, lastRow;
+        
+        s.setCursorName(getNextCursorName());
+        ResultSet rs =
+            s.executeQuery("select * from t1");
+        
+        rs.last();
+        lastRow = rs.getRow();
+        
+        rs.beforeFirst();
+        
+        rs.next();
+        
+        // Test that it is possible to move to next row from insertRow
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.next();
+        assertEquals("CurrentPosition should be " + (currentPosition + 1), 
+                rs.getRow(), currentPosition + 1);
+        // should be able to delete the row
+        rs.deleteRow();
+
+        // Test that it is possible to move using relative from insertRow
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.relative(2);
+        assertEquals("CurrentPosition should be " + (currentPosition + 2), 
+                rs.getRow(), currentPosition + 2);
+        // should be able to delete the row
+        rs.deleteRow();
+
+        // Test that it is possible to move using absolute from insertRow
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.absolute(6);
+        assertEquals("CurrentPosition should be 6", rs.getRow(), 6);
+        // should be able to delete the row
+        rs.deleteRow();
+
+        // Test that it is possible to move to previous row from insertRow
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.previous();
+        assertEquals("CurrentPosition should be " + (currentPosition - 1), 
+                rs.getRow(), currentPosition - 1);
+        // should be able to delete the row
+        rs.deleteRow();
+
+        // Test that it is possible to move to first row from insertRow
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.first();
+        assertEquals("CurrentPosition should be 1", rs.getRow(), 1);
+        assertTrue("isFirst() should return true", rs.isFirst());
+        // should be able to delete the row
+        rs.deleteRow();
+
+        // Test that it is possible to move to last row from insertRow
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.last();
+        assertEquals("CurrentPosition should be " + lastRow, 
+                rs.getRow(), lastRow);
+        assertTrue("isLast() should return true", rs.isLast());
+        // should be able to delete the row
+        rs.deleteRow();
+
+        // Test that it is possible to move beforeFirst from insertRow
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.beforeFirst();
+        assertTrue("isBeforeFirst() should return true", rs.isBeforeFirst());
+        rs.next();
+        assertEquals("CurrentPosition should be 1", rs.getRow(), 1);
+        assertTrue("isFirst() should return true", rs.isFirst());
+
+        // Test that it is possible to move afterLast from insertRow
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.afterLast();
+        assertTrue("isAfterLast() should return true", rs.isAfterLast());
+        rs.previous();
+        assertEquals("CurrentPosition should be " + lastRow, 
+                rs.getRow(), lastRow);
+        assertTrue("isLast() should return true", rs.isLast());
+
+        // Test that it is possible to insert a row and move back to current row
+        rs.previous();
+        currentPosition = rs.getRow();
+        rs.moveToInsertRow();
+        rs.updateInt(1, currentPosition + 1000);
+        rs.insertRow();
+        rs.moveToCurrentRow();
+        assertEquals("CurrentPosition should be " + currentPosition, 
+                rs.getRow(), currentPosition);
+
+        
+        try {
+            rs.moveToInsertRow();
+            rs.updateInt(1, currentPosition + 2000);
+            rs.updateRow();
+        } catch (SQLException se) {
+            assertEquals("Expected exception", 
+                    se.getSQLState().substring(0, 5), 
+                    INVALID_CURSOR_STATE_NO_CURRENT_ROW);
+        }
+        
+        try {
+            rs.moveToInsertRow();
+            rs.updateInt(1, currentPosition + 2000);
+            rs.deleteRow();
+        } catch (SQLException se) {
+            assertEquals("Expected exception", 
+                    se.getSQLState().substring(0, 5), 
+                    INVALID_CURSOR_STATE_NO_CURRENT_ROW);
+        }
+        
+        try {
+            rs.moveToCurrentRow();
+            rs.updateInt(1, currentPosition + 2000);
+            rs.insertRow();
+        } catch (SQLException se) {
+            assertEquals("Expected exception", 
+                    se.getSQLState().substring(0, 5), 
+                    CURSOR_NOT_POSITIONED_ON_INSERT_ROW);
+        }
+        
+        rs.close();
+        
+        s.close();
+    }
+    
+    /**
      *  Test that you can scroll forward and update indexed records
      *  in the scrollable ResultSet (not using FOR UPDATE).
      */



Mime
View raw message