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);
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();
+ }
+
}
+