diff --git a/src/interfaces/jdbc/org/postgresql/ResultSet.java b/src/interfaces/jdbc/org/postgresql/ResultSet.java index 768a489e6f31d202627f92dbabaa6ec6ee0b7e8b..6e533eed01086d75d5737edd986990ab32c50c71 100644 --- a/src/interfaces/jdbc/org/postgresql/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/ResultSet.java @@ -255,5 +255,10 @@ public abstract class ResultSet else this.warnings = warnings; } + protected void checkResultSet( int column ) throws SQLException + { + if ( this_row == null ) throw new PSQLException("postgresql.res.nextrequired"); + if ( column < 1 || column > fields.length ) throw new PSQLException("postgresql.res.colrange" ); + } } diff --git a/src/interfaces/jdbc/org/postgresql/errors.properties b/src/interfaces/jdbc/org/postgresql/errors.properties index f8054dd1fab55d698b928a88a2da56710e272850..7c5b32eb3f1d254973cffc9e59fffe3434906a61 100644 --- a/src/interfaces/jdbc/org/postgresql/errors.properties +++ b/src/interfaces/jdbc/org/postgresql/errors.properties @@ -58,6 +58,7 @@ postgresql.res.badtime:Bad Time {0} postgresql.res.badtimestamp:Bad Timestamp Format at {0} in {1} postgresql.res.colname:The column name {0} not found. postgresql.res.colrange:The column index is out of range. +postgresql.res.nextrequired:Result set not positioned properly, perhaps you need to call next(). postgresql.serial.interface:You cannot serialize an interface. postgresql.serial.namelength:Class & Package name length cannot be longer than 32 characters. {0} is {1} characters. postgresql.serial.noclass:No class found for {0}. diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java index 949b919541e39fb90ce46b8b37e5e008c7021327..02a5195b9545c645312250328fb4bfb45a5b259b 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java @@ -155,9 +155,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public String getString(int columnIndex) throws SQLException { - if (columnIndex < 1 || columnIndex > fields.length) - throw new PSQLException("postgresql.res.colrange"); - + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) return null; @@ -388,9 +386,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public byte[] getBytes(int columnIndex) throws SQLException { - if (columnIndex < 1 || columnIndex > fields.length) - throw new PSQLException("postgresql.res.colrange"); - + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (!wasNullFlag) { @@ -623,6 +619,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public InputStream getAsciiStream(int columnIndex) throws SQLException { + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) return null; @@ -665,6 +662,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public InputStream getUnicodeStream(int columnIndex) throws SQLException { + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) return null; @@ -707,6 +705,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public InputStream getBinaryStream(int columnIndex) throws SQLException { + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) return null; diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java index a983284e5cc2a783ae1316727addaab8df15059d..dd12cda7da7beb1dc5f791254f6adbd10b531064 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java @@ -162,9 +162,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public String getString(int columnIndex) throws SQLException { - if (columnIndex < 1 || columnIndex > fields.length) - throw new PSQLException("postgresql.res.colrange"); - + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) return null; @@ -315,9 +313,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public byte[] getBytes(int columnIndex) throws SQLException { - if (columnIndex < 1 || columnIndex > fields.length) - throw new PSQLException("postgresql.res.colrange"); - + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (!wasNullFlag) { @@ -424,6 +420,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public InputStream getAsciiStream(int columnIndex) throws SQLException { + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) return null; @@ -469,6 +466,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public InputStream getUnicodeStream(int columnIndex) throws SQLException { + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) return null; @@ -511,6 +509,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu */ public InputStream getBinaryStream(int columnIndex) throws SQLException { + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) return null; @@ -724,8 +723,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu { Field field; - if (columnIndex < 1 || columnIndex > fields.length) - throw new PSQLException("postgresql.res.colrange"); + checkResultSet( columnIndex ); wasNullFlag = (this_row[columnIndex - 1] == null); if (wasNullFlag) @@ -941,6 +939,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu public java.io.Reader getCharacterStream(int i) throws SQLException { + checkResultSet( i ); wasNullFlag = (this_row[i - 1] == null); if (wasNullFlag) return null;