Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebb9332

Browse files
author
Barry Lind
committed
Attached is a patch against the CVS repository that fixes the ResultSet absolute() problem.
There's also a little fix for the getRow() method. While fixingabsolute(), I noticed that getRow() wasn't quite following the spec: itwasn't returning 0 when the ResultSet wasn't positioned on a row. I'vestarted a ResultSet test case and included it as well.Liam Stewart
1 parentc97a787 commitebb9332

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -836,23 +836,27 @@ public boolean absolute(int index) throws SQLException
836836
//if index<0, count from the end of the result set, but check
837837
//to be sure that it is not beyond the first index
838838
if (index <0)
839+
{
839840
if (index >= -rows_size)
840841
internalIndex =rows_size +index;
841842
else
842843
{
843844
beforeFirst();
844845
returnfalse;
845846
}
846-
847-
//must be the case that index>0,
848-
//find the correct place, assuming that
849-
//the index is not too large
850-
if (index <=rows_size)
851-
internalIndex =index -1;
847+
}
852848
else
853849
{
854-
afterLast();
855-
returnfalse;
850+
//must be the case that index>0,
851+
//find the correct place, assuming that
852+
//the index is not too large
853+
if (index <=rows_size)
854+
internalIndex =index -1;
855+
else
856+
{
857+
afterLast();
858+
returnfalse;
859+
}
856860
}
857861

858862
current_row =internalIndex;
@@ -1074,6 +1078,11 @@ public Ref getRef(int i) throws SQLException
10741078

10751079
publicintgetRow()throwsSQLException
10761080
{
1081+
finalintrows_size =rows.size();
1082+
1083+
if (current_row <0 ||current_row >=rows_size)
1084+
return0;
1085+
10771086
returncurrent_row +1;
10781087
}
10791088

‎src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public static TestSuite suite()
205205
// Connectivity/Protocols
206206

207207
// ResultSet
208+
suite.addTestSuite(ResultSetTest.class);
208209

209210
// Time, Date, Timestamp
210211
suite.addTestSuite(DateTest.class);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
packageorg.postgresql.test.jdbc2;
2+
3+
importorg.postgresql.test.JDBC2Tests;
4+
importjunit.framework.TestCase;
5+
importjava.io.*;
6+
importjava.sql.*;
7+
8+
/**
9+
* ResultSet tests.
10+
*/
11+
publicclassResultSetTestextendsTestCase
12+
{
13+
privateConnectioncon;
14+
15+
publicResultSetTest(Stringname)
16+
{
17+
super(name);
18+
}
19+
20+
protectedvoidsetUp()throwsException
21+
{
22+
con =JDBC2Tests.openDB();
23+
Statementstmt =con.createStatement();
24+
25+
JDBC2Tests.createTable(con,"testrs","id integer");
26+
27+
stmt.executeUpdate("INSERT INTO testrs VALUES (1)");
28+
stmt.executeUpdate("INSERT INTO testrs VALUES (2)");
29+
stmt.executeUpdate("INSERT INTO testrs VALUES (3)");
30+
stmt.executeUpdate("INSERT INTO testrs VALUES (4)");
31+
stmt.executeUpdate("INSERT INTO testrs VALUES (6)");
32+
stmt.executeUpdate("INSERT INTO testrs VALUES (9)");
33+
34+
stmt.close();
35+
}
36+
37+
protectedvoidtearDown()throwsException
38+
{
39+
JDBC2Tests.dropTable(con,"testrs");
40+
JDBC2Tests.closeDB(con);
41+
}
42+
43+
publicvoidtestAbsolute()throwsException
44+
{
45+
Statementstmt =con.createStatement();
46+
ResultSetrs =stmt.executeQuery("SELECT * FROM testrs");
47+
48+
assertTrue(rs.absolute(-1));
49+
assertEquals(6,rs.getRow());
50+
51+
assertTrue(rs.absolute(1));
52+
assertEquals(1,rs.getRow());
53+
54+
assertTrue(!rs.absolute(-10));
55+
assertEquals(0,rs.getRow());
56+
assertTrue(rs.next());
57+
assertEquals(1,rs.getRow());
58+
59+
assertTrue(!rs.absolute(10));
60+
assertEquals(0,rs.getRow());
61+
assertTrue(rs.previous());
62+
assertEquals(6,rs.getRow());
63+
64+
stmt.close();
65+
}
66+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp