Updatable ResultSets need to check for an empty ResultSet because
authorKris Jurka <[email protected]>
Fri, 22 Apr 2005 14:48:18 +0000 (14:48 +0000)
committerKris Jurka <[email protected]>
Fri, 22 Apr 2005 14:48:18 +0000 (14:48 +0000)
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.

src/interfaces/jdbc/org/postgresql/errors.properties
src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java

index 15689894f18939de970f8c7abc6adbfade1b7611..2ede089016eaba935ff5189cd89d6182dc1c1ceb 100644 (file)
@@ -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, <some_type>)' was made.
 postgresql.call.noinout:PostgreSQL only supports function return value [@ 1] (no OUT or INOUT arguments)
index 38dc25dc2b02e173b443dd200a519394d187b162..259d0ae1ded1af13c310d186cf62fc49c48fb119 100644 (file)
@@ -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");
                }