aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Lind <barry@xythos.com>2001-11-14 04:11:37 +0000
committerBarry Lind <barry@xythos.com>2001-11-14 04:11:37 +0000
commitebb93323bbf7c62aeff283cd5991071ee8c575fa (patch)
tree22b370d8461b48acd90ae011e23c4ebbbca03b0f /src
parentc97a787e85df6bd6b7a6ff5cc35a75ec0601de7c (diff)
downloadpostgresql-ebb93323bbf7c62aeff283cd5991071ee8c575fa.tar.gz
postgresql-ebb93323bbf7c62aeff283cd5991071ee8c575fa.zip
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 fixing absolute(), I noticed that getRow() wasn't quite following the spec: it wasn't returning 0 when the ResultSet wasn't positioned on a row. I've started a ResultSet test case and included it as well. Liam Stewart
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java25
-rw-r--r--src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java1
-rw-r--r--src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java66
3 files changed, 84 insertions, 8 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
index c5a64296245..e98cef86600 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
@@ -836,6 +836,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
//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
@@ -843,16 +844,19 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
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;
+ //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 = internalIndex;
@@ -1074,6 +1078,11 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public int getRow() throws SQLException
{
+ final int rows_size = rows.size();
+
+ if (current_row < 0 || current_row >= rows_size)
+ return 0;
+
return current_row + 1;
}
diff --git a/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java b/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java
index 1f299ceb16c..2512192c981 100644
--- a/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java
+++ b/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java
@@ -205,6 +205,7 @@ public class JDBC2Tests extends TestSuite
// Connectivity/Protocols
// ResultSet
+ suite.addTestSuite(ResultSetTest.class);
// Time, Date, Timestamp
suite.addTestSuite(DateTest.class);
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java
new file mode 100644
index 00000000000..e4ec7928c95
--- /dev/null
+++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ResultSetTest.java
@@ -0,0 +1,66 @@
+package org.postgresql.test.jdbc2;
+
+import org.postgresql.test.JDBC2Tests;
+import junit.framework.TestCase;
+import java.io.*;
+import java.sql.*;
+
+/**
+ * ResultSet tests.
+ */
+public class ResultSetTest extends TestCase
+{
+ private Connection con;
+
+ public ResultSetTest(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ con = JDBC2Tests.openDB();
+ Statement stmt = con.createStatement();
+
+ JDBC2Tests.createTable(con, "testrs", "id integer");
+
+ stmt.executeUpdate("INSERT INTO testrs VALUES (1)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (2)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (3)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (4)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (6)");
+ stmt.executeUpdate("INSERT INTO testrs VALUES (9)");
+
+ stmt.close();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ JDBC2Tests.dropTable(con, "testrs");
+ JDBC2Tests.closeDB(con);
+ }
+
+ public void testAbsolute() throws Exception
+ {
+ Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT * FROM testrs");
+
+ assertTrue(rs.absolute(-1));
+ assertEquals(6, rs.getRow());
+
+ assertTrue(rs.absolute(1));
+ assertEquals(1, rs.getRow());
+
+ assertTrue(!rs.absolute(-10));
+ assertEquals(0, rs.getRow());
+ assertTrue(rs.next());
+ assertEquals(1, rs.getRow());
+
+ assertTrue(!rs.absolute(10));
+ assertEquals(0, rs.getRow());
+ assertTrue(rs.previous());
+ assertEquals(6, rs.getRow());
+
+ stmt.close();
+ }
+}