Skip to content

Commit d3ef753

Browse files
committed
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
1 parent bd29cb0 commit d3ef753

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -801,16 +801,34 @@ public int findColumn(String columnName) throws SQLException
801801

802802
public boolean absolute(int index) throws SQLException
803803
{
804-
// Peter: Added because negative indices read from the end of the
805-
// ResultSet
806-
if(index<0)
807-
index=rows.size()+index;
808-
809-
if (index > rows.size())
804+
// index is 1-based, but internally we use 0-based indices
805+
int internalIndex;
806+
807+
if (index==0)
808+
throw new SQLException("Cannot move to index of 0");
809+
810+
//if index<0, count from the end of the result set, but check
811+
//to be sure that it is not beyond the first index
812+
if (index<0)
813+
if (index>=-rows.size())
814+
internalIndex=rows.size()+index;
815+
else {
816+
beforeFirst();
817+
return false;
818+
}
819+
820+
//must be the case that index>0,
821+
//find the correct place, assuming that
822+
//the index is not too large
823+
if (index<=rows.size())
824+
internalIndex = index-1;
825+
else {
826+
afterLast();
810827
return false;
811-
812-
current_row=index;
813-
this_row = (byte [][])rows.elementAt(index);
828+
}
829+
830+
current_row=internalIndex;
831+
this_row = (byte [][])rows.elementAt(internalIndex);
814832
return true;
815833
}
816834

@@ -1041,7 +1059,8 @@ public void refreshRow() throws SQLException
10411059
// Peter: Implemented in 7.0
10421060
public boolean relative(int rows) throws SQLException
10431061
{
1044-
return absolute(current_row+rows);
1062+
//have to add 1 since absolute expects a 1-based index
1063+
return absolute(current_row+1+rows);
10451064
}
10461065

10471066
public boolean rowDeleted() throws SQLException

0 commit comments

Comments
 (0)