Issue Details (XML | Word | Printable)

Key: DERBY-1323
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Dag H. Wanvik
Reporter: Dag H. Wanvik
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

Detectability methods rowUpdated, rowInserted, rowDeleted can be called from illegal states in both clients

Created: 12/May/06 09:51 PM   Updated: 30/Jun/09 04:12 PM
Return to search
Component/s: JDBC, Network Client
Affects Version/s: 10.2.1.6
Fix Version/s: 10.2.1.6

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works DERBY-1323-1.diff 2006-05-15 10:08 AM Dag H. Wanvik 19 kB
File Licensed for inclusion in ASF works DERBY-1323-1.stat 2006-05-15 10:08 AM Dag H. Wanvik 0.9 kB
File Licensed for inclusion in ASF works DERBY-1323-2.diff 2006-05-19 06:09 AM Dag H. Wanvik 19 kB
File Licensed for inclusion in ASF works DERBY-1323-2.stat 2006-05-19 06:09 AM Dag H. Wanvik 0.9 kB
Java Source File Licensed for inclusion in ASF works Main.java 2006-05-12 09:53 PM Dag H. Wanvik 8 kB

Issue & fix info: Release Note Needed
Resolution Date: 23/May/06 06:45 PM


 Description  « Hide
Please see enclosed repro.

These detectability methods fail to check that they can be called in
some states. In the repro, calls are allowed while on insert row and
when after last row. These should both fail. Both clients have the
same problem. All three detectability methods have the same problem.
(repro only shows it for a subset of the cases).


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Dag H. Wanvik made changes - 12/May/06 09:53 PM
Field Original Value New Value
Attachment Main.java [ 12327416 ]
Dag H. Wanvik added a comment - 15/May/06 10:08 AM
This patch adds checks for the cases described below, for both
clients, in the JDBC ResultSet API methods rowUpdated, rowDeleted and
rowInserted.

In all cases, the exception "no current row" (SQLState 24000) is
thrown. A new test has been added to jdbcapi/SURTest.java to exercise
all cases.

The JDBC API and specification does not state explicitly what to do in
these situations, as far as I can see. For the "forward only" case, a
slight, albeit unlikely regression is introduced. I will back out this
change if people think it is risky. I view it as a correction, though.
This is the reason for the changed master files for
lang/updatableResultSet.java.

Now, the cases:

For result sets of type TYPE_SCROLL_INSENSITIVE and CONCUR_UPDATABLE:
- before positioning
- on insertRow
- on beforeFirst row
- on afterLast row
- after deleteRow, before new positioning

For result sets of type TYPE_FORWARD_ONLY and CONCUR_UPDATABLE:
- before positioning (***)
- on insertRow
- after updateRow, before new positioning (*)
- after deleteRow, before new positioning (**)
- after rs emptied out (***)

Detectability is currently not implemented for "forward only" result
sets and the methods always used to return false, even in the states
indicated. The new checks added by this patch (needed for scrollable
result sets) introduce a slight regression, in that calls may now
throw an exception. Cases (*) and (**) broke the regression test as
mentioned, but I think the use of detection methods in these states is
rather meaningless, since Derby can no longer access a row in these
cases anyway - until a next() is performed. Even less problematic
should be {TYPE_FORWARD_ONLY, CONCUR_READ_ONLY} in the cases (***).

I have run derbyall with no related errors and the patch is ready for
review.

Dag H. Wanvik made changes - 15/May/06 10:08 AM
Attachment DERBY-1323-1.diff [ 12331894 ]
Attachment DERBY-1323-1.stat [ 12331893 ]
Dag H. Wanvik made changes - 15/May/06 10:10 AM
Derby Info [Patch Available, Existing Application Impact, Release Note Needed]
Fernanda Pizzorno added a comment - 16/May/06 06:29 PM
Review:

The patch looks good. I just have a couple of questions.

1. java/client/org/apache/derby/client/am/ResultSet.java

This check has been added in several places:

+ if (isOnInsertRow_ || !isValidCursorPosition_) {
+ throw new SqlException
+ (agent_.logWriter_,
+ new ClientMessageId(SQLState.NO_CURRENT_ROW));
+ }

Could it be put in a private method?

2. java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java

Is it really necessary to use reflection?

Dag H. Wanvik added a comment - 19/May/06 06:09 AM
This is version 2 of this patch. It addresses both comments of Fernanda's review.
Changes were only made to client code and SURTest.java, so i ran
derbynetclientmats again as well as SURTest on embedded without
problems(*).

(*) derbynetclientmats failed on NSinSameJVM.java and DerbyNetNewServer,
though - I don't think it is related; I ran on a sane build from the classes directory with
Sun JDK 1.5.

Dag H. Wanvik made changes - 19/May/06 06:09 AM
Attachment DERBY-1323-2.stat [ 12334296 ]
Attachment DERBY-1323-2.diff [ 12334297 ]
Dag H. Wanvik made changes - 19/May/06 08:19 AM
Assignee Dag H. Wanvik [ dagw ]
Fernanda Pizzorno added a comment - 22/May/06 09:49 PM
All of my comments have been addressed in the DERBY-1323-2.diff.

The following changes seem unnecessary to me:
[...]
+ checkForClosedResultSet();
+ checkPositionedOnPlainRow();
+
             boolean rowInserted = false;
- checkForClosedResultSet();
[...]
- boolean rowDeleted = (resultSetType_ == ResultSet.TYPE_SCROLL_INSENSITIVE) ?
- cursor_.getIsUpdateDeleteHole() :
- false;
+ boolean rowDeleted =
+ (resultSetType_ == ResultSet.TYPE_SCROLL_INSENSITIVE) ?
+ cursor_.getIsUpdateDeleteHole() : false;
[...]

I have seen comments against cosmetic changes before, but I am not sure we have a policy against it.

Repository Revision Date User Message
ASF #408875 Tue May 23 11:43:31 UTC 2006 bernt DERBY-1323 Detectability methods rowUpdated, rowInserted, rowDeleted can be called from illegal states in both clients. Submitted by Dag H. Wanvik
Files Changed
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/updatableResultSet.out
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk14/updatableResultSet.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_foundation/updatableResultSet.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/updatableResultSet.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/updatableResultSet.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java
MODIFY /db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/updatableResultSet.out
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java

Bernt M. Johnsen added a comment - 23/May/06 06:45 PM
Committed revision 408875.

Bernt M. Johnsen made changes - 23/May/06 06:45 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Dag H. Wanvik made changes - 06/Jun/06 09:37 PM
Status Resolved [ 5 ] Closed [ 6 ]
Dag H. Wanvik added a comment - 18/Sep/06 03:52 PM
Release note for this issue:


PROBLEM

For a JDBC ResultSet with type TYPE_FORWARD_ONLY, the methods
rowUpdated, rowDeleted and rowInserted could previously be called
while not on a row, i.e. before positioning in the result set, while
on insertRow, after updateRow before new positioning, after deleteRow
before new positioning and when after last row. This is now
disallowed.

SYMPTOMS

Calls to any of these methods while not on a row will now throw
SQLException with SQLState 24000.

CAUSE

Derby now disallows these calls when not on a row.

SOLUTION

Change the application to not call these methods unless on a row. Note
that using them at all is rather meaningless for a ResultSet of type
TYPE_FORWARD_ONLY since the returned result will always be 'false'.
This is because once you modify a row, it can no longer be accessed,
you need to move to the next row, if there is one, to get a new
current row. Presently in Derby, these methods are only really
meaningfully useed for result sets of type TYPE_SCROLL_INSENSITIVE and
of concurrency CONCUR_UPDATABLE in which case updated and deleted rows
can be detected.

WORKAROUND

None.

Repository Revision Date User Message
ASF #447505 Mon Sep 18 19:06:53 UTC 2006 rhillegas DERBY-1860: Incorporate release notes for DERBY-1295, DERBY-1314, and DERBY-1323 submitted by Fernanda, Knut Anders, and Dag.
Files Changed
MODIFY /db/derby/code/branches/10.2/RELEASE-NOTES.html

Dag H. Wanvik made changes - 05/May/08 03:02 PM
Derby Info [Patch Available, Release Note Needed, Existing Application Impact] [Existing Application Impact, Release Note Needed]
Dag H. Wanvik made changes - 30/Jun/09 04:12 PM
Issue & fix info [Existing Application Impact, Release Note Needed] [Release Note Needed]