You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Andreas Korneliussen (JIRA)" <de...@db.apache.org> on 2006/05/03 13:44:46 UTC

[jira] Created: (DERBY-1277) Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable updatable resultsets

Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable updatable resultsets
---------------------------------------------------------------------------------------------------------------------------------------

         Key: DERBY-1277
         URL: http://issues.apache.org/jira/browse/DERBY-1277
     Project: Derby
        Type: Bug

  Components: SQL  
    Versions: 10.2.0.0    
    Reporter: Andreas Korneliussen
    Priority: Minor


In scrollable updatable resultset, a call to rs.isLast() may cause rs.getXXX() return values from the last row, instead of for the current row.  This may be related to the fact that on calls to isLast() the scroll insensitive resultset moves to the last row, and then moves back to the current row (see DERBY-1276 for related information). The call to isLast() seems to have a sideeffect when the resultset is updatable.

I have test which does the following:
        Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
        ResultSet rs = stmt1.executeQuery("select * from testRelative");
        
        rs.next(); // First Record
        System.out.println("First record is: " + rs.getString("name"));
        rs.relative(2); // Third Record        
        System.out.println("Third record is: " + rs.getString("name"));
        System.out.println(" isLast=" + rs.isLast());
        System.out.println("Third record is: " + rs.getString("name"));

The output is:
First record is: work1
Third record is: work3
 isLast=false
Third record is: work4
isLast()==false

The issue may also be reproduced by applying the following patch to testRelative:

Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (revision 399224)
+++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (working copy)
@@ -60,7 +60,7 @@
                        pStmt.executeBatch();
                        con.commit();

-                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
+                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                        rs = stmt1.executeQuery("select * from testRelative");

                        rs.next(); // First Record


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (DERBY-1277) Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets

Posted by "Knut Anders Hatlen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-1277?page=all ]
     
Knut Anders Hatlen resolved DERBY-1277:
---------------------------------------

    Fix Version: 10.2.0.0
     Resolution: Fixed

The patch looks very good. All tests ran cleanly. Committed revision 400212.

> Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets
> -----------------------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-1277
>          URL: http://issues.apache.org/jira/browse/DERBY-1277
>      Project: Derby
>         Type: Bug

>   Components: SQL
>     Versions: 10.2.0.0, 10.1.2.1
>     Reporter: Andreas Korneliussen
>     Assignee: Andreas Korneliussen
>      Fix For: 10.2.0.0
>  Attachments: DERBY-1277.diff, DERBY-1277.stat
>
> In scrollable updatable resultset, a call to rs.isLast() may cause rs.getXXX() return values from the last row, instead of for the current row.  This may be related to the fact that on calls to isLast() the scroll insensitive resultset moves to the last row, and then moves back to the current row (see DERBY-1276 for related information). The call to isLast() seems to have a sideeffect when the resultset is updatable.
> I have test which does the following:
>         Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>         ResultSet rs = stmt1.executeQuery("select * from testRelative");
>         
>         rs.next(); // First Record
>         System.out.println("First record is: " + rs.getString("name"));
>         rs.relative(2); // Third Record        
>         System.out.println("Third record is: " + rs.getString("name"));
>         System.out.println(" isLast=" + rs.isLast());
>         System.out.println("Third record is: " + rs.getString("name"));
> The output is:
> First record is: work1
> Third record is: work3
>  isLast=false
> Third record is: work4
> isLast()==false
> The issue may also be reproduced by applying the following patch to testRelative:
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (revision 399224)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (working copy)
> @@ -60,7 +60,7 @@
>                         pStmt.executeBatch();
>                         con.commit();
> -                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
> +                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>                         rs = stmt1.executeQuery("select * from testRelative");
>                         rs.next(); // First Record

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-1277) Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets

Posted by "Andreas Korneliussen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-1277?page=all ]

Andreas Korneliussen updated DERBY-1277:
----------------------------------------

    Attachment: DERBY-1277.diff
                DERBY-1277.stat

Attaching a fix, were ScrollInsensitiveResultSet do not return ExecRow from the source resultset, only from the hashtable. This ensures that navigation in source resultsets do not affect the current row of the scrollinsensitive resultset.

Also extended the test testRelative to test with concurrency mode CONCUR_UPDATABLE, and fixed it so that it can run in derbynetclient framework.


> Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets
> -----------------------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-1277
>          URL: http://issues.apache.org/jira/browse/DERBY-1277
>      Project: Derby
>         Type: Bug

>   Components: SQL
>     Versions: 10.2.0.0, 10.1.2.1
>     Reporter: Andreas Korneliussen
>     Assignee: Andreas Korneliussen
>  Attachments: DERBY-1277.diff, DERBY-1277.stat
>
> In scrollable updatable resultset, a call to rs.isLast() may cause rs.getXXX() return values from the last row, instead of for the current row.  This may be related to the fact that on calls to isLast() the scroll insensitive resultset moves to the last row, and then moves back to the current row (see DERBY-1276 for related information). The call to isLast() seems to have a sideeffect when the resultset is updatable.
> I have test which does the following:
>         Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>         ResultSet rs = stmt1.executeQuery("select * from testRelative");
>         
>         rs.next(); // First Record
>         System.out.println("First record is: " + rs.getString("name"));
>         rs.relative(2); // Third Record        
>         System.out.println("Third record is: " + rs.getString("name"));
>         System.out.println(" isLast=" + rs.isLast());
>         System.out.println("Third record is: " + rs.getString("name"));
> The output is:
> First record is: work1
> Third record is: work3
>  isLast=false
> Third record is: work4
> isLast()==false
> The issue may also be reproduced by applying the following patch to testRelative:
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (revision 399224)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (working copy)
> @@ -60,7 +60,7 @@
>                         pStmt.executeBatch();
>                         con.commit();
> -                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
> +                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>                         rs = stmt1.executeQuery("select * from testRelative");
>                         rs.next(); // First Record

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-1277) Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets

Posted by "Andreas Korneliussen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-1277?page=all ]

Andreas Korneliussen updated DERBY-1277:
----------------------------------------

    Derby Info: [Patch Available]

A patch is now available for review.

> Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets
> -----------------------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-1277
>          URL: http://issues.apache.org/jira/browse/DERBY-1277
>      Project: Derby
>         Type: Bug

>   Components: SQL
>     Versions: 10.2.0.0, 10.1.2.1
>     Reporter: Andreas Korneliussen
>     Assignee: Andreas Korneliussen
>  Attachments: DERBY-1277.diff, DERBY-1277.stat
>
> In scrollable updatable resultset, a call to rs.isLast() may cause rs.getXXX() return values from the last row, instead of for the current row.  This may be related to the fact that on calls to isLast() the scroll insensitive resultset moves to the last row, and then moves back to the current row (see DERBY-1276 for related information). The call to isLast() seems to have a sideeffect when the resultset is updatable.
> I have test which does the following:
>         Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>         ResultSet rs = stmt1.executeQuery("select * from testRelative");
>         
>         rs.next(); // First Record
>         System.out.println("First record is: " + rs.getString("name"));
>         rs.relative(2); // Third Record        
>         System.out.println("Third record is: " + rs.getString("name"));
>         System.out.println(" isLast=" + rs.isLast());
>         System.out.println("Third record is: " + rs.getString("name"));
> The output is:
> First record is: work1
> Third record is: work3
>  isLast=false
> Third record is: work4
> isLast()==false
> The issue may also be reproduced by applying the following patch to testRelative:
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (revision 399224)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (working copy)
> @@ -60,7 +60,7 @@
>                         pStmt.executeBatch();
>                         con.commit();
> -                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
> +                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>                         rs = stmt1.executeQuery("select * from testRelative");
>                         rs.next(); // First Record

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Assigned: (DERBY-1277) Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable updatable resultsets

Posted by "Andreas Korneliussen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-1277?page=all ]

Andreas Korneliussen reassigned DERBY-1277:
-------------------------------------------

    Assign To: Andreas Korneliussen

> Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable updatable resultsets
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-1277
>          URL: http://issues.apache.org/jira/browse/DERBY-1277
>      Project: Derby
>         Type: Bug

>   Components: SQL
>     Versions: 10.2.0.0
>     Reporter: Andreas Korneliussen
>     Assignee: Andreas Korneliussen
>     Priority: Minor

>
> In scrollable updatable resultset, a call to rs.isLast() may cause rs.getXXX() return values from the last row, instead of for the current row.  This may be related to the fact that on calls to isLast() the scroll insensitive resultset moves to the last row, and then moves back to the current row (see DERBY-1276 for related information). The call to isLast() seems to have a sideeffect when the resultset is updatable.
> I have test which does the following:
>         Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>         ResultSet rs = stmt1.executeQuery("select * from testRelative");
>         
>         rs.next(); // First Record
>         System.out.println("First record is: " + rs.getString("name"));
>         rs.relative(2); // Third Record        
>         System.out.println("Third record is: " + rs.getString("name"));
>         System.out.println(" isLast=" + rs.isLast());
>         System.out.println("Third record is: " + rs.getString("name"));
> The output is:
> First record is: work1
> Third record is: work3
>  isLast=false
> Third record is: work4
> isLast()==false
> The issue may also be reproduced by applying the following patch to testRelative:
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (revision 399224)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (working copy)
> @@ -60,7 +60,7 @@
>                         pStmt.executeBatch();
>                         con.commit();
> -                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
> +                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>                         rs = stmt1.executeQuery("select * from testRelative");
>                         rs.next(); // First Record

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-1277) Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets

Posted by "Andreas Korneliussen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-1277?page=all ]

Andreas Korneliussen updated DERBY-1277:
----------------------------------------

     Summary: Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets  (was: Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable updatable resultsets)
     Version: 10.1.2.1
    Priority: Major  (was: Minor)

After analyzing this bug, I found that it is caused by TableScanResultSet and EmbedResultSet sharing DataValueColumn descriptors, and that the call to isLast() will make TableScanResultSet modify the data.

This bug was first only detected in updatable resultset, because they will have use TableScanResultSet as source, while read-only resultsets use BulkTableScanResultSet as source.  

If the select statement contains "FOR UPDATE", also read-only scrollable resultsets will use a TableScanResultSet as source. 

The bug is reproducable in Derby 10.1.2, ie. by modifying the select statement to contain "FOR UPDATE", and open the resultset with concurrency CONCUR_READ_ONLY.

I will upload a patch, were ScrollInsensitiveResultSet is modified so that it will give a reference to data which is in the hashtable.



> Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets
> -----------------------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-1277
>          URL: http://issues.apache.org/jira/browse/DERBY-1277
>      Project: Derby
>         Type: Bug

>   Components: SQL
>     Versions: 10.2.0.0, 10.1.2.1
>     Reporter: Andreas Korneliussen
>     Assignee: Andreas Korneliussen

>
> In scrollable updatable resultset, a call to rs.isLast() may cause rs.getXXX() return values from the last row, instead of for the current row.  This may be related to the fact that on calls to isLast() the scroll insensitive resultset moves to the last row, and then moves back to the current row (see DERBY-1276 for related information). The call to isLast() seems to have a sideeffect when the resultset is updatable.
> I have test which does the following:
>         Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>         ResultSet rs = stmt1.executeQuery("select * from testRelative");
>         
>         rs.next(); // First Record
>         System.out.println("First record is: " + rs.getString("name"));
>         rs.relative(2); // Third Record        
>         System.out.println("Third record is: " + rs.getString("name"));
>         System.out.println(" isLast=" + rs.isLast());
>         System.out.println("Third record is: " + rs.getString("name"));
> The output is:
> First record is: work1
> Third record is: work3
>  isLast=false
> Third record is: work4
> isLast()==false
> The issue may also be reproduced by applying the following patch to testRelative:
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (revision 399224)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (working copy)
> @@ -60,7 +60,7 @@
>                         pStmt.executeBatch();
>                         con.commit();
> -                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
> +                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>                         rs = stmt1.executeQuery("select * from testRelative");
>                         rs.next(); // First Record

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (DERBY-1277) Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets

Posted by "Andreas Korneliussen (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-1277?page=all ]
     
Andreas Korneliussen closed DERBY-1277:
---------------------------------------


> Call to rs.isLast() may cause rs.getXXX() return values from the last row instead of the current row in scrollable resultsets
> -----------------------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-1277
>          URL: http://issues.apache.org/jira/browse/DERBY-1277
>      Project: Derby
>         Type: Bug

>   Components: SQL
>     Versions: 10.2.0.0, 10.1.2.1
>     Reporter: Andreas Korneliussen
>     Assignee: Andreas Korneliussen
>      Fix For: 10.2.0.0
>  Attachments: DERBY-1277.diff, DERBY-1277.stat
>
> In scrollable updatable resultset, a call to rs.isLast() may cause rs.getXXX() return values from the last row, instead of for the current row.  This may be related to the fact that on calls to isLast() the scroll insensitive resultset moves to the last row, and then moves back to the current row (see DERBY-1276 for related information). The call to isLast() seems to have a sideeffect when the resultset is updatable.
> I have test which does the following:
>         Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>         ResultSet rs = stmt1.executeQuery("select * from testRelative");
>         
>         rs.next(); // First Record
>         System.out.println("First record is: " + rs.getString("name"));
>         rs.relative(2); // Third Record        
>         System.out.println("Third record is: " + rs.getString("name"));
>         System.out.println(" isLast=" + rs.isLast());
>         System.out.println("Third record is: " + rs.getString("name"));
> The output is:
> First record is: work1
> Third record is: work3
>  isLast=false
> Third record is: work4
> isLast()==false
> The issue may also be reproduced by applying the following patch to testRelative:
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (revision 399224)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java  (working copy)
> @@ -60,7 +60,7 @@
>                         pStmt.executeBatch();
>                         con.commit();
> -                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
> +                       stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
>                         rs = stmt1.executeQuery("select * from testRelative");
>                         rs.next(); // First Record

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira