* Copyright (c) 2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.22.2.1 2003/12/12 17:59:08 davec Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.22.2.2 2004/02/03 05:25:36 jurka Exp $
*
*-------------------------------------------------------------------------
*/
if (rows == null)
throw new PSQLException("postgresql.con.closed", PSQLState.CONNECTION_DOES_NOT_EXIST);
- if (++current_row >= rows.size())
+ if (current_row+1 >= rows.size())
{
String cursorName = statement.getFetchingCursorName();
- if (cursorName == null || lastFetchSize == 0 || rows.size() < lastFetchSize)
+ if (cursorName == null || lastFetchSize == 0 || rows.size() < lastFetchSize) {
+ current_row = rows.size();
return false; // Not doing a cursor-based fetch or the last fetch was the end of the query
+ }
// Use the ref to the statement to get
// the details we need to do another cursor
// Otherwise reset the counter and let it go on...
current_row = 0;
+ } else {
+ current_row++;
}
this_row = (byte [][])rows.elementAt(current_row);
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.25.2.2 2003/12/18 03:35:55 davec Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.25.2.3 2004/02/03 05:25:37 jurka Exp $
*
*-------------------------------------------------------------------------
*/
public boolean previous() throws SQLException
{
- if (--current_row < 0)
+ if (current_row-1 < 0) {
+ current_row = -1;
return false;
+ } else {
+ current_row--;
+ }
this_row = (byte[][]) rows.elementAt(current_row);
rowBuffer = new byte[this_row.length][];
System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
+import java.sql.SQLException;
import junit.framework.TestCase;
fail("Exception expected.");
}
}
-
+
+ public void testZeroRowResultPositioning() throws SQLException
+ {
+ Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs = stmt.executeQuery("SELECT * FROM pg_database WHERE datname='nonexistantdatabase'");
+ assertEquals(rs.previous(),false);
+ assertEquals(rs.previous(),false);
+ assertEquals(rs.next(),false);
+ assertEquals(rs.next(),false);
+ assertEquals(rs.next(),false);
+ assertEquals(rs.next(),false);
+ assertEquals(rs.next(),false);
+ assertEquals(rs.previous(),false);
+ assertEquals(rs.first(),false);
+ assertEquals(rs.last(),false);
+ assertEquals(rs.getRow(),0);
+ assertEquals(rs.absolute(1),false);
+ assertEquals(rs.relative(1),false);
+ assertEquals(rs.isBeforeFirst(),false);
+ assertEquals(rs.isAfterLast(),false);
+ assertEquals(rs.isFirst(),false);
+ assertEquals(rs.isLast(),false);
+ rs.close();
+ stmt.close();
+ }
+
+ public void testRowResultPositioning() throws SQLException
+ {
+ Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
+ // Create a one row result set.
+ ResultSet rs = stmt.executeQuery("SELECT * FROM pg_database WHERE datname='template1'");
+ assertTrue(rs.isBeforeFirst());
+ assertTrue(rs.next());
+ assertTrue(rs.isFirst());
+ assertTrue(rs.isLast());
+ assertTrue(!rs.next());
+ assertTrue(rs.isAfterLast());
+ assertTrue(rs.previous());
+ assertTrue(rs.absolute(1));
+ rs.close();
+ stmt.close();
+ }
+
}
+