aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/interfaces/jdbc/org/postgresql/errors.properties1
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java9
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java16
-rw-r--r--src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java51
4 files changed, 74 insertions, 3 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/errors.properties b/src/interfaces/jdbc/org/postgresql/errors.properties
index a0b7ddee3e2..15689894f18 100644
--- a/src/interfaces/jdbc/org/postgresql/errors.properties
+++ b/src/interfaces/jdbc/org/postgresql/errors.properties
@@ -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.
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
index 5216ff6df33..c07a34a4abf 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
@@ -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;
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index b44e301854d..2667a373b43 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -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);
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java
index b3284d4df28..bba9755eb0a 100644
--- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java
+++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/UpdateableResultTest.java
@@ -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);