Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ee21548

Browse files
author
Dave Cramer
committed
Added a check for not calling next() before getting objects from the result set,
moved the check for columnIndex into same call check at the top of all getXXX added appropriate error
1 parent c422b5c commit ee21548

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

src/interfaces/jdbc/org/postgresql/ResultSet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,10 @@ public void addWarnings(SQLWarning warnings) {
255255
else
256256
this.warnings = warnings;
257257
}
258+
protected void checkResultSet( int column ) throws SQLException
259+
{
260+
if ( this_row == null ) throw new PSQLException("postgresql.res.nextrequired");
261+
if ( column < 1 || column > fields.length ) throw new PSQLException("postgresql.res.colrange" );
262+
}
258263
}
259264

src/interfaces/jdbc/org/postgresql/errors.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ postgresql.res.badtime:Bad Time {0}
5858
postgresql.res.badtimestamp:Bad Timestamp Format at {0} in {1}
5959
postgresql.res.colname:The column name {0} not found.
6060
postgresql.res.colrange:The column index is out of range.
61+
postgresql.res.nextrequired:Result set not positioned properly, perhaps you need to call next().
6162
postgresql.serial.interface:You cannot serialize an interface.
6263
postgresql.serial.namelength:Class & Package name length cannot be longer than 32 characters. {0} is {1} characters.
6364
postgresql.serial.noclass:No class found for {0}.

src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ public boolean wasNull() throws SQLException
155155
*/
156156
public String getString(int columnIndex) throws SQLException
157157
{
158-
if (columnIndex < 1 || columnIndex > fields.length)
159-
throw new PSQLException("postgresql.res.colrange");
160-
158+
checkResultSet( columnIndex );
161159
wasNullFlag = (this_row[columnIndex - 1] == null);
162160
if (wasNullFlag)
163161
return null;
@@ -388,9 +386,7 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
388386
*/
389387
public byte[] getBytes(int columnIndex) throws SQLException
390388
{
391-
if (columnIndex < 1 || columnIndex > fields.length)
392-
throw new PSQLException("postgresql.res.colrange");
393-
389+
checkResultSet( columnIndex );
394390
wasNullFlag = (this_row[columnIndex - 1] == null);
395391
if (!wasNullFlag)
396392
{
@@ -623,6 +619,7 @@ else if (slen == 19)
623619
*/
624620
public InputStream getAsciiStream(int columnIndex) throws SQLException
625621
{
622+
checkResultSet( columnIndex );
626623
wasNullFlag = (this_row[columnIndex - 1] == null);
627624
if (wasNullFlag)
628625
return null;
@@ -665,6 +662,7 @@ public InputStream getAsciiStream(int columnIndex) throws SQLException
665662
*/
666663
public InputStream getUnicodeStream(int columnIndex) throws SQLException
667664
{
665+
checkResultSet( columnIndex );
668666
wasNullFlag = (this_row[columnIndex - 1] == null);
669667
if (wasNullFlag)
670668
return null;
@@ -707,6 +705,7 @@ public InputStream getUnicodeStream(int columnIndex) throws SQLException
707705
*/
708706
public InputStream getBinaryStream(int columnIndex) throws SQLException
709707
{
708+
checkResultSet( columnIndex );
710709
wasNullFlag = (this_row[columnIndex - 1] == null);
711710
if (wasNullFlag)
712711
return null;

src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ public boolean wasNull() throws SQLException
162162
*/
163163
public String getString(int columnIndex) throws SQLException
164164
{
165-
if (columnIndex < 1 || columnIndex > fields.length)
166-
throw new PSQLException("postgresql.res.colrange");
167-
165+
checkResultSet( columnIndex );
168166
wasNullFlag = (this_row[columnIndex - 1] == null);
169167
if (wasNullFlag)
170168
return null;
@@ -315,9 +313,7 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
315313
*/
316314
public byte[] getBytes(int columnIndex) throws SQLException
317315
{
318-
if (columnIndex < 1 || columnIndex > fields.length)
319-
throw new PSQLException("postgresql.res.colrange");
320-
316+
checkResultSet( columnIndex );
321317
wasNullFlag = (this_row[columnIndex - 1] == null);
322318
if (!wasNullFlag)
323319
{
@@ -424,6 +420,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
424420
*/
425421
public InputStream getAsciiStream(int columnIndex) throws SQLException
426422
{
423+
checkResultSet( columnIndex );
427424
wasNullFlag = (this_row[columnIndex - 1] == null);
428425
if (wasNullFlag)
429426
return null;
@@ -469,6 +466,7 @@ public InputStream getAsciiStream(int columnIndex) throws SQLException
469466
*/
470467
public InputStream getUnicodeStream(int columnIndex) throws SQLException
471468
{
469+
checkResultSet( columnIndex );
472470
wasNullFlag = (this_row[columnIndex - 1] == null);
473471
if (wasNullFlag)
474472
return null;
@@ -511,6 +509,7 @@ public InputStream getUnicodeStream(int columnIndex) throws SQLException
511509
*/
512510
public InputStream getBinaryStream(int columnIndex) throws SQLException
513511
{
512+
checkResultSet( columnIndex );
514513
wasNullFlag = (this_row[columnIndex - 1] == null);
515514
if (wasNullFlag)
516515
return null;
@@ -724,8 +723,7 @@ public Object getObject(int columnIndex) throws SQLException
724723
{
725724
Field field;
726725

727-
if (columnIndex < 1 || columnIndex > fields.length)
728-
throw new PSQLException("postgresql.res.colrange");
726+
checkResultSet( columnIndex );
729727

730728
wasNullFlag = (this_row[columnIndex - 1] == null);
731729
if (wasNullFlag)
@@ -941,6 +939,7 @@ public java.io.Reader getCharacterStream(String columnName) throws SQLException
941939

942940
public java.io.Reader getCharacterStream(int i) throws SQLException
943941
{
942+
checkResultSet( i );
944943
wasNullFlag = (this_row[i - 1] == null);
945944
if (wasNullFlag)
946945
return null;

0 commit comments

Comments
 (0)