1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-15 19:21:59 +03:00

Fix some problems with result sets positioned before the start or

after the end of results.  You could still call a number of methods
on them like getXXX, updateXXX, and updateRow().
This commit is contained in:
Kris Jurka
2004-06-21 03:12:01 +00:00
parent 922c2638e4
commit bb95de1f2a
4 changed files with 74 additions and 3 deletions

View File

@ -92,6 +92,7 @@ postgresql.updateable.oninsertrow:Can not call deleteRow() when on insert row
postgresql.updateable.emptydelete:Can't deleteRow() on empty result set
postgresql.updateable.beforestartdelete:Before start of result set. Can not call deleteRow().
postgresql.updateable.afterlastdelete:After end of result set. Can not call deleteRow().
postgresql.updateable.badupdateposition:Cannot update the result set because it is either before the start or after the end of the results.
postgresql.updateable.notoninsertrow:Not on insert row.
postgresql.updateable.ioerror:Input Stream Error - {0}
postgresql.call.noreturntype:A CallableStatement Function was declared but no call to 'registerOutParameter (1, <some_type>)' was made.

View File

@ -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.3 2004/03/29 17:47:47 barry Exp $
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.22.2.4 2004/06/21 03:11:37 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@ -138,6 +138,8 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
String cursorName = statement.getFetchingCursorName();
if (cursorName == null || lastFetchSize == 0 || rows.size() < lastFetchSize) {
current_row = rows.size();
this_row = null;
rowBuffer = null;
return false; // Not doing a cursor-based fetch or the last fetch was the end of the query
}
@ -160,8 +162,11 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
// Test the new rows array.
lastFetchSize = fetchSize;
if (rows.size() == 0)
if (rows.size() == 0) {
this_row = null;
rowBuffer = null;
return false;
}
// Otherwise reset the counter and let it go on...
current_row = 0;

View File

@ -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.7 2004/06/21 02:01:11 jurka Exp $
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.25.2.8 2004/06/21 03:11:49 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@ -225,6 +225,8 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
current_row = rows_size;
onInsertRow = false;
this_row = null;
rowBuffer = null;
}
@ -234,6 +236,8 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
current_row = -1;
onInsertRow = false;
this_row = null;
rowBuffer = null;
}
@ -500,6 +504,8 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
{
if (current_row-1 < 0) {
current_row = -1;
this_row = null;
rowBuffer = null;
return false;
} else {
current_row--;
@ -1073,6 +1079,10 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
{
throw new PSQLException( "postgresql.updateable.notupdateable" );
}
if (isBeforeFirst() || isAfterLast())
{
throw new PSQLException("postgresql.updateable.badupdateposition");
}
if (doingUpdates)
{
@ -1580,6 +1590,10 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
{
throw new PSQLException( "postgresql.updateable.notupdateable" );
}
if (!onInsertRow && (isBeforeFirst() || isAfterLast()))
{
throw new PSQLException("postgresql.updateable.badupdateposition");
}
doingUpdates = !onInsertRow;
if (value == null)
updateNull(columnIndex);

View File

@ -118,6 +118,57 @@ public class UpdateableResultTest extends TestCase
st.close();
}
private void checkPositioning(ResultSet rs) throws SQLException
{
try {
rs.getInt(1);
fail("Can't use an incorrectly positioned result set.");
} catch (SQLException sqle) { }
try {
rs.updateInt(1,2);
fail("Can't use an incorrectly positioned result set.");
} catch (SQLException sqle) { }
try {
rs.updateRow();
fail("Can't use an incorrectly positioned result set.");
} catch (SQLException sqle) { }
try {
rs.deleteRow();
fail("Can't use an incorrectly positioned result set.");
} catch (SQLException sqle) { }
}
public void testPositioning() throws SQLException
{
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT id1,name1 FROM second");
checkPositioning(rs);
assertTrue(rs.next());
rs.beforeFirst();
checkPositioning(rs);
rs.afterLast();
checkPositioning(rs);
rs.beforeFirst();
assertTrue(rs.next());
assertFalse(rs.next());
checkPositioning(rs);
rs.afterLast();
assertTrue(rs.previous());
assertFalse(rs.previous());
checkPositioning(rs);
rs.close();
stmt.close();
}
public void testUpdateStreams() throws SQLException, UnsupportedEncodingException
{
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);