From: Kris Jurka Date: Fri, 22 Apr 2005 14:48:18 +0000 (+0000) Subject: Updatable ResultSets need to check for an empty ResultSet because X-Git-Tag: REL7_4_8~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a44f99024c43fa7cb4fb24e62033bc5704e0355c;p=thirdparty%2Fpostgresql.git Updatable ResultSets need to check for an empty ResultSet because isBeforeFirst and isAfterLast both return false for an empty result so the checking to make sure the user is on a valid row wasn't working. Also don't allow an insert without specifying at least one column value because INSERT INTO tab() values() is a syntax error. --- diff --git a/src/interfaces/jdbc/org/postgresql/errors.properties b/src/interfaces/jdbc/org/postgresql/errors.properties index 15689894f18..2ede089016e 100644 --- a/src/interfaces/jdbc/org/postgresql/errors.properties +++ b/src/interfaces/jdbc/org/postgresql/errors.properties @@ -94,6 +94,7 @@ postgresql.updateable.beforestartdelete:Before start of result set. Can not call 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.noinsertvalues:You must specify at least one column value to insert a row. postgresql.updateable.ioerror:Input Stream Error - {0} postgresql.call.noreturntype:A CallableStatement Function was declared but no call to 'registerOutParameter (1, )' was made. postgresql.call.noinout:PostgreSQL only supports function return value [@ 1] (no OUT or INOUT arguments) diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java index 6e182b43bbc..f9660445fba 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.11 2005/04/22 14:36:48 jurka Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.25.2.12 2005/04/22 14:48:18 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -617,6 +617,10 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra { throw new PSQLException( "postgresql.updateable.notoninsertrow" ); } + if (updateValues.size() == 0) + { + throw new PSQLException( "postgresql.updateable.noinsertvalues" ); + } else { @@ -1011,7 +1015,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra if (onInsertRow) throw new PSQLException("postgresql.res.oninsertrow"); - if (isBeforeFirst() || isAfterLast()) + if (isBeforeFirst() || isAfterLast() || rows.size() == 0) return; StringBuffer selectSQL = new StringBuffer( "select "); @@ -1081,7 +1085,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra { throw new PSQLException( "postgresql.updateable.notupdateable" ); } - if (isBeforeFirst() || isAfterLast()) + if (isBeforeFirst() || isAfterLast() || rows.size() == 0) { throw new PSQLException("postgresql.updateable.badupdateposition"); } @@ -1592,7 +1596,7 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra { throw new PSQLException( "postgresql.updateable.notupdateable" ); } - if (!onInsertRow && (isBeforeFirst() || isAfterLast())) + if (!onInsertRow && (isBeforeFirst() || isAfterLast() || rows.size() == 0)) { throw new PSQLException("postgresql.updateable.badupdateposition"); }