mirror of
https://github.com/postgres/postgres.git
synced 2025-05-18 17:41:14 +03:00
ResultSet.next() and previous() incremented or decremented the
internal current_row variable regardless of wether they succeeded or not. This generated some ArrayIndexOutOfBoundsExceptions when the errorneous adjustment current_row led to out of range values. Per report from Fischer Krisztian.
This commit is contained in:
parent
9287630fbc
commit
1a92a4c10c
@ -9,7 +9,7 @@
|
||||
* 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 $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -137,11 +137,13 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
|
||||
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
|
||||
@ -167,6 +169,8 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
|
||||
|
||||
// Otherwise reset the counter and let it go on...
|
||||
current_row = 0;
|
||||
} else {
|
||||
current_row++;
|
||||
}
|
||||
|
||||
this_row = (byte [][])rows.elementAt(current_row);
|
||||
|
@ -9,7 +9,7 @@
|
||||
* 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 $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -490,8 +490,12 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
|
||||
|
||||
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);
|
||||
|
@ -4,6 +4,7 @@ import org.postgresql.test.TestUtil;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@ -286,4 +287,47 @@ public class ResultSetTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user