diff options
author | Bruce Momjian <bruce@momjian.us> | 2000-06-09 17:27:57 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2000-06-09 17:27:57 +0000 |
commit | d3ef753686384256c0a1439b3afb023bd96589ff (patch) | |
tree | 5a310ed521cec03ac9e92cf396326edddb0e62ff /src | |
parent | bd29cb0ee740459d2a389186c1c5cb37d3eb5ad4 (diff) | |
download | postgresql-d3ef753686384256c0a1439b3afb023bd96589ff.tar.gz postgresql-d3ef753686384256c0a1439b3afb023bd96589ff.zip |
This patch fixes the 0-based/1-based result set indexing problem for
absolute. It also makes it more compliant with the interface
specification in Sun's documentation;
1. absolute(0) should throw an exception.
2. absolute(>num-records) should set the current row to after the last
record in addition to returning false.
3. absolute(<num-records) should set the current row to before the first
record in addition to returning false.
These operations in the existing code just return false and don't change
current_row.
These changes required a minor change to relative(int) since it calls
absolute(int)
The attached patch is against the cvs repository tree as of this morning.
Also, who is in charge of maintaining the jdbc driver? I'm working on
getArray for the jdbc2 driver, but it's going to require three more
classes to be added to the driver, and thus three more source files
in the repository. Is there someone I can contact directly to ask about
this?
Travis Bauer | CS Grad Student | IU |www.cs.indiana.edu/~trbauer
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java index 1b957bd9cbf..85cb3c1f434 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java @@ -801,16 +801,34 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu public boolean absolute(int index) throws SQLException { - // Peter: Added because negative indices read from the end of the - // ResultSet - if(index<0) - index=rows.size()+index; - - if (index > rows.size()) + // index is 1-based, but internally we use 0-based indices + int internalIndex; + + if (index==0) + throw new SQLException("Cannot move to index of 0"); + + //if index<0, count from the end of the result set, but check + //to be sure that it is not beyond the first index + if (index<0) + if (index>=-rows.size()) + internalIndex=rows.size()+index; + else { + beforeFirst(); + return false; + } + + //must be the case that index>0, + //find the correct place, assuming that + //the index is not too large + if (index<=rows.size()) + internalIndex = index-1; + else { + afterLast(); return false; - - current_row=index; - this_row = (byte [][])rows.elementAt(index); + } + + current_row=internalIndex; + this_row = (byte [][])rows.elementAt(internalIndex); return true; } @@ -1041,7 +1059,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu // Peter: Implemented in 7.0 public boolean relative(int rows) throws SQLException { - return absolute(current_row+rows); + //have to add 1 since absolute expects a 1-based index + return absolute(current_row+1+rows); } public boolean rowDeleted() throws SQLException |