Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee21548

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 callcheck at the top of all getXXXadded appropriate error
1 parentc422b5c commitee21548

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+
protectedvoidcheckResultSet(intcolumn )throwsSQLException
259+
{
260+
if (this_row ==null )thrownewPSQLException("postgresql.res.nextrequired");
261+
if (column <1 ||column >fields.length )thrownewPSQLException("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
publicStringgetString(intcolumnIndex)throwsSQLException
157157
{
158-
if (columnIndex <1 ||columnIndex >fields.length)
159-
thrownewPSQLException("postgresql.res.colrange");
160-
158+
checkResultSet(columnIndex );
161159
wasNullFlag = (this_row[columnIndex -1] ==null);
162160
if (wasNullFlag)
163161
returnnull;
@@ -388,9 +386,7 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
388386
*/
389387
publicbyte[]getBytes(intcolumnIndex)throwsSQLException
390388
{
391-
if (columnIndex <1 ||columnIndex >fields.length)
392-
thrownewPSQLException("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
publicInputStreamgetAsciiStream(intcolumnIndex)throwsSQLException
625621
{
622+
checkResultSet(columnIndex );
626623
wasNullFlag = (this_row[columnIndex -1] ==null);
627624
if (wasNullFlag)
628625
returnnull;
@@ -665,6 +662,7 @@ public InputStream getAsciiStream(int columnIndex) throws SQLException
665662
*/
666663
publicInputStreamgetUnicodeStream(intcolumnIndex)throwsSQLException
667664
{
665+
checkResultSet(columnIndex );
668666
wasNullFlag = (this_row[columnIndex -1] ==null);
669667
if (wasNullFlag)
670668
returnnull;
@@ -707,6 +705,7 @@ public InputStream getUnicodeStream(int columnIndex) throws SQLException
707705
*/
708706
publicInputStreamgetBinaryStream(intcolumnIndex)throwsSQLException
709707
{
708+
checkResultSet(columnIndex );
710709
wasNullFlag = (this_row[columnIndex -1] ==null);
711710
if (wasNullFlag)
712711
returnnull;

‎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
publicStringgetString(intcolumnIndex)throwsSQLException
164164
{
165-
if (columnIndex <1 ||columnIndex >fields.length)
166-
thrownewPSQLException("postgresql.res.colrange");
167-
165+
checkResultSet(columnIndex );
168166
wasNullFlag = (this_row[columnIndex -1] ==null);
169167
if (wasNullFlag)
170168
returnnull;
@@ -315,9 +313,7 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
315313
*/
316314
publicbyte[]getBytes(intcolumnIndex)throwsSQLException
317315
{
318-
if (columnIndex <1 ||columnIndex >fields.length)
319-
thrownewPSQLException("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
publicInputStreamgetAsciiStream(intcolumnIndex)throwsSQLException
426422
{
423+
checkResultSet(columnIndex );
427424
wasNullFlag = (this_row[columnIndex -1] ==null);
428425
if (wasNullFlag)
429426
returnnull;
@@ -469,6 +466,7 @@ public InputStream getAsciiStream(int columnIndex) throws SQLException
469466
*/
470467
publicInputStreamgetUnicodeStream(intcolumnIndex)throwsSQLException
471468
{
469+
checkResultSet(columnIndex );
472470
wasNullFlag = (this_row[columnIndex -1] ==null);
473471
if (wasNullFlag)
474472
returnnull;
@@ -511,6 +509,7 @@ public InputStream getUnicodeStream(int columnIndex) throws SQLException
511509
*/
512510
publicInputStreamgetBinaryStream(intcolumnIndex)throwsSQLException
513511
{
512+
checkResultSet(columnIndex );
514513
wasNullFlag = (this_row[columnIndex -1] ==null);
515514
if (wasNullFlag)
516515
returnnull;
@@ -724,8 +723,7 @@ public Object getObject(int columnIndex) throws SQLException
724723
{
725724
Fieldfield;
726725

727-
if (columnIndex <1 ||columnIndex >fields.length)
728-
thrownewPSQLException("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
publicjava.io.ReadergetCharacterStream(inti)throwsSQLException
943941
{
942+
checkResultSet(i );
944943
wasNullFlag = (this_row[i -1] ==null);
945944
if (wasNullFlag)
946945
returnnull;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp