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

Commit5cdf771

Browse files
author
Barry Lind
committed
Additional SQLState work for JDBC - thanks to Kim Ho at Redhat for input on this
Modified Files: jdbc/build.xml jdbc/org/postgresql/core/QueryExecutor.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java jdbc/org/postgresql/util/PSQLState.java
1 parentfcdf0e2 commit5cdf771

File tree

7 files changed

+50
-44
lines changed

7 files changed

+50
-44
lines changed

‎src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2003, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/QueryExecutor.java,v 1.24 2003/09/08 17:30:22 barry Exp $
9+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/QueryExecutor.java,v 1.25 2003/09/09 10:49:16 barry Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -340,7 +340,7 @@ private void sendQueryV3() throws SQLException
340340
}
341341
catch (IOExceptione)
342342
{
343-
thrownewPSQLException("postgresql.con.ioerror",e);
343+
thrownewPSQLException("postgresql.con.ioerror",PSQLState.CONNECTION_FAILURE_DURING_TRANSACTION,e);
344344
}
345345
}
346346

@@ -370,7 +370,7 @@ private void sendQueryV2() throws SQLException
370370
}
371371
catch (IOExceptione)
372372
{
373-
thrownewPSQLException("postgresql.con.ioerror",e);
373+
thrownewPSQLException("postgresql.con.ioerror",PSQLState.CONNECTION_FAILURE_DURING_TRANSACTION,e);
374374
}
375375
}
376376

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Copyright (c) 2003, PostgreSQL Global Development Group
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.24 2003/09/08 17:30:22 barry Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.25 2003/09/09 10:49:16 barry Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -252,7 +252,7 @@ private void openConnectionV3(String p_host, int p_port, Properties p_info, Stri
252252

253253
case'N':
254254
// Server does not support ssl
255-
thrownewPSQLException("postgresql.con.sslnotsupported");
255+
thrownewPSQLException("postgresql.con.sslnotsupported",PSQLState.CONNECTION_FAILURE);
256256

257257
case'S':
258258
// Server supports ssl
@@ -262,7 +262,7 @@ private void openConnectionV3(String p_host, int p_port, Properties p_info, Stri
262262
break;
263263

264264
default:
265-
thrownewPSQLException("postgresql.con.sslfail");
265+
thrownewPSQLException("postgresql.con.sslfail",PSQLState.CONNECTION_FAILURE);
266266
}
267267
}
268268
}
@@ -559,7 +559,7 @@ private void openConnectionV2(String host, int port, Properties info, String dat
559559

560560
case'N':
561561
// Server does not support ssl
562-
thrownewPSQLException("postgresql.con.sslnotsupported");
562+
thrownewPSQLException("postgresql.con.sslnotsupported",PSQLState.CONNECTION_FAILURE);
563563

564564
case'S':
565565
// Server supports ssl
@@ -569,7 +569,7 @@ private void openConnectionV2(String host, int port, Properties info, String dat
569569
break;
570570

571571
default:
572-
thrownewPSQLException("postgresql.con.sslfail");
572+
thrownewPSQLException("postgresql.con.sslfail",PSQLState.CONNECTION_FAILURE);
573573
}
574574
}
575575
}
@@ -1610,7 +1610,7 @@ public int getSQLType(int oid) throws SQLException
16101610
}
16111611
BaseResultSetresult =execSQL(sql);
16121612
if (result.getColumnCount() !=1 ||result.getTupleCount() !=1) {
1613-
thrownewPSQLException("postgresql.unexpected");
1613+
thrownewPSQLException("postgresql.unexpected",PSQLState.UNEXPECTED_ERROR);
16141614
}
16151615
result.next();
16161616
pgType =result.getString(1);
@@ -1651,7 +1651,7 @@ public int getPGType(String typeName) throws SQLException
16511651
}
16521652
BaseResultSetresult =execSQL(sql);
16531653
if (result.getColumnCount() !=1 ||result.getTupleCount() !=1)
1654-
thrownewPSQLException("postgresql.unexpected");
1654+
thrownewPSQLException("postgresql.unexpected",PSQLState.UNEXPECTED_ERROR);
16551655
result.next();
16561656
oid =Integer.parseInt(result.getString(1));
16571657
typeOidCache.put(typeName,newInteger(oid));

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
importorg.postgresql.core.BaseStatement;
77
importorg.postgresql.core.Field;
88
importorg.postgresql.util.PSQLException;
9+
importorg.postgresql.util.PSQLState;
910
importorg.postgresql.Driver;
1011

1112
publicabstractclassAbstractJdbc1DatabaseMetaData
@@ -43,7 +44,7 @@ protected int getMaxIndexKeys() throws SQLException {
4344
Stringsql ="SELECT t1.typlen/t2.typlen FROM "+from+" t1.typelem=t2.oid AND t1.typname='oidvector'";
4445
ResultSetrs =connection.createStatement().executeQuery(sql);
4546
if (!rs.next()) {
46-
thrownewPSQLException("postgresql.unexpected");
47+
thrownewPSQLException("postgresql.unexpected",PSQLState.UNEXPECTED_ERROR);
4748
}
4849
INDEX_MAX_KEYS =rs.getInt(1);
4950
rs.close();
@@ -61,7 +62,7 @@ protected int getMaxNameLength() throws SQLException {
6162
}
6263
ResultSetrs =connection.createStatement().executeQuery(sql);
6364
if (!rs.next()) {
64-
thrownewPSQLException("postgresql.unexpected");
65+
thrownewPSQLException("postgresql.unexpected",PSQLState.UNEXPECTED_ERROR);
6566
}
6667
NAMEDATALEN =rs.getInt("typlen");
6768
rs.close();

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Copyright (c) 2003, PostgreSQL Global Development Group
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.16 2003/09/08 17:30:22 barry Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.17 2003/09/09 10:49:16 barry Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -242,7 +242,7 @@ public short getShort(int columnIndex) throws SQLException
242242
}
243243
catch (NumberFormatExceptione)
244244
{
245-
thrownewPSQLException("postgresql.res.badshort",s);
245+
thrownewPSQLException("postgresql.res.badshort",PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,s);
246246
}
247247
}
248248
return0;// SQL NULL
@@ -368,7 +368,7 @@ public InputStream getAsciiStream(int columnIndex) throws SQLException
368368
}
369369
catch (UnsupportedEncodingExceptionl_uee)
370370
{
371-
thrownewPSQLException("postgresql.unusual",l_uee);
371+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,l_uee);
372372
}
373373
}
374374
else
@@ -399,7 +399,7 @@ public InputStream getUnicodeStream(int columnIndex) throws SQLException
399399
}
400400
catch (UnsupportedEncodingExceptionl_uee)
401401
{
402-
thrownewPSQLException("postgresql.unusual",l_uee);
402+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,l_uee);
403403
}
404404
}
405405
else
@@ -814,7 +814,7 @@ public static int toInt(String s) throws SQLException
814814
}
815815
catch (NumberFormatExceptione)
816816
{
817-
thrownewPSQLException ("postgresql.res.badint",s);
817+
thrownewPSQLException ("postgresql.res.badint",PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,s);
818818
}
819819
}
820820
return0;// SQL NULL
@@ -831,7 +831,7 @@ public static long toLong(String s) throws SQLException
831831
}
832832
catch (NumberFormatExceptione)
833833
{
834-
thrownewPSQLException ("postgresql.res.badlong",s);
834+
thrownewPSQLException ("postgresql.res.badlong",PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,s);
835835
}
836836
}
837837
return0;// SQL NULL
@@ -849,7 +849,7 @@ public static BigDecimal toBigDecimal(String s, int scale) throws SQLException
849849
}
850850
catch (NumberFormatExceptione)
851851
{
852-
thrownewPSQLException ("postgresql.res.badbigdec",s);
852+
thrownewPSQLException ("postgresql.res.badbigdec",PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,s);
853853
}
854854
if (scale == -1)
855855
returnval;
@@ -859,7 +859,7 @@ public static BigDecimal toBigDecimal(String s, int scale) throws SQLException
859859
}
860860
catch (ArithmeticExceptione)
861861
{
862-
thrownewPSQLException ("postgresql.res.badbigdec",s);
862+
thrownewPSQLException ("postgresql.res.badbigdec",PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,s);
863863
}
864864
}
865865
returnnull;// SQL NULL
@@ -876,7 +876,7 @@ public static float toFloat(String s) throws SQLException
876876
}
877877
catch (NumberFormatExceptione)
878878
{
879-
thrownewPSQLException ("postgresql.res.badfloat",s);
879+
thrownewPSQLException ("postgresql.res.badfloat",PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,s);
880880
}
881881
}
882882
return0;// SQL NULL
@@ -893,7 +893,7 @@ public static double toDouble(String s) throws SQLException
893893
}
894894
catch (NumberFormatExceptione)
895895
{
896-
thrownewPSQLException ("postgresql.res.baddouble",s);
896+
thrownewPSQLException ("postgresql.res.baddouble",PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,s);
897897
}
898898
}
899899
return0;// SQL NULL
@@ -912,7 +912,7 @@ public static java.sql.Date toDate(String s) throws SQLException
912912
}
913913
catch (NumberFormatExceptione)
914914
{
915-
thrownewPSQLException("postgresql.res.baddate",s);
915+
thrownewPSQLException("postgresql.res.baddate",PSQLState.BAD_DATETIME_FORMAT,s);
916916
}
917917
}
918918

@@ -954,7 +954,7 @@ else if (l_millis < 100)
954954
}
955955
catch (NumberFormatExceptione)
956956
{
957-
thrownewPSQLException("postgresql.res.badtime",s);
957+
thrownewPSQLException("postgresql.res.badtime",PSQLState.BAD_DATETIME_FORMAT,s);
958958
}
959959
}
960960

@@ -1055,7 +1055,7 @@ public static Timestamp toTimestamp(String s, BaseResultSet resultSet, String pg
10551055
}
10561056
catch (NumberFormatExceptione)
10571057
{
1058-
thrownewPSQLException("postgresql.unusual",e);
1058+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,e);
10591059
}
10601060

10611061
// The nanos field stores nanoseconds. Adjust the parsed
@@ -1140,7 +1140,7 @@ else if (slen == 19)
11401140
}
11411141
catch (ParseExceptione)
11421142
{
1143-
thrownewPSQLException("postgresql.res.badtimestamp",PSQLState.UNKNOWN_STATE,newInteger(e.getErrorOffset()),s);
1143+
thrownewPSQLException("postgresql.res.badtimestamp",PSQLState.BAD_DATETIME_FORMAT,newInteger(e.getErrorOffset()),s);
11441144
}
11451145
}
11461146
}

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
importjava.sql.Types;
2727
importjava.util.Vector;
2828

29-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.34 2003/09/08 17:30:22 barry Exp $
29+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.35 2003/09/09 10:49:16 barry Exp $
3030
* This class defines methods of the jdbc1 specification. This class is
3131
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
3232
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -203,7 +203,7 @@ public java.sql.ResultSet executeQuery() throws SQLException
203203
while (result !=null && !result.reallyResultSet())
204204
result = (BaseResultSet)result.getNext();
205205
if (result ==null)
206-
thrownewPSQLException("postgresql.stat.noresult");
206+
thrownewPSQLException("postgresql.stat.noresult",PSQLState.NO_DATA);
207207
return (ResultSet)result;
208208
}
209209

@@ -443,9 +443,9 @@ else if (fetchSize > 0 && !connection.getAutoCommit())
443443
if (isFunction)
444444
{
445445
if (!result.reallyResultSet())
446-
thrownewPSQLException("postgresql.call.noreturnval");
446+
thrownewPSQLException("postgresql.call.noreturnval",PSQLState.NO_DATA);
447447
if (!result.next ())
448-
thrownewPSQLException ("postgresql.call.noreturnval");
448+
thrownewPSQLException ("postgresql.call.noreturnval",PSQLState.NO_DATA);
449449
callResult =result.getObject(1);
450450
intcolumnType =result.getMetaData().getColumnType(1);
451451
if (columnType !=functionReturnType)
@@ -1293,11 +1293,11 @@ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws
12931293
}
12941294
catch (UnsupportedEncodingExceptionl_uee)
12951295
{
1296-
thrownewPSQLException("postgresql.unusual",l_uee);
1296+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,l_uee);
12971297
}
12981298
catch (IOExceptionl_ioe)
12991299
{
1300-
thrownewPSQLException("postgresql.unusual",l_ioe);
1300+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,l_ioe);
13011301
}
13021302
}
13031303
else
@@ -1342,11 +1342,11 @@ public void setUnicodeStream(int parameterIndex, InputStream x, int length) thro
13421342
}
13431343
catch (UnsupportedEncodingExceptionl_uee)
13441344
{
1345-
thrownewPSQLException("postgresql.unusual",l_uee);
1345+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,l_uee);
13461346
}
13471347
catch (IOExceptionl_ioe)
13481348
{
1349-
thrownewPSQLException("postgresql.unusual",l_ioe);
1349+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,l_ioe);
13501350
}
13511351
}
13521352
else
@@ -1389,7 +1389,7 @@ public void setBinaryStream(int parameterIndex, InputStream x, int length) throw
13891389
}
13901390
catch (IOExceptionl_ioe)
13911391
{
1392-
thrownewPSQLException("postgresql.unusual",l_ioe);
1392+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,l_ioe);
13931393
}
13941394
if (l_bytesRead ==length)
13951395
{
@@ -1429,7 +1429,7 @@ public void setBinaryStream(int parameterIndex, InputStream x, int length) throw
14291429
}
14301430
catch (IOExceptionse)
14311431
{
1432-
thrownewPSQLException("postgresql.unusual",se);
1432+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,se);
14331433
}
14341434
// lob is closed by the stream so don't call lob.close()
14351435
setInt(parameterIndex,oid);
@@ -2097,7 +2097,7 @@ private java.sql.Date dateFromString (String s) throws SQLException
20972097
}
20982098
catch (Exceptione)
20992099
{
2100-
thrownewPSQLException("postgresql.format.baddate",PSQLState.UNKNOWN_STATE,s ,"yyyy-MM-dd[-tz]");
2100+
thrownewPSQLException("postgresql.format.baddate",PSQLState.BAD_DATETIME_FORMAT,s ,"yyyy-MM-dd[-tz]");
21012101
}
21022102
timezone =0;
21032103
if (timezoneLocation>7 &&timezoneLocation+3 ==s.length())
@@ -2128,7 +2128,7 @@ private java.sql.Time timeFromString (String s) throws SQLException
21282128
}
21292129
catch (Exceptione)
21302130
{
2131-
thrownewPSQLException("postgresql.format.badtime",PSQLState.UNKNOWN_STATE,s,"HH:mm:ss[-tz]");
2131+
thrownewPSQLException("postgresql.format.badtime",PSQLState.BAD_DATETIME_FORMAT,s,"HH:mm:ss[-tz]");
21322132
}
21332133
timezone =0;
21342134
if (timezoneLocation != -1 &&timezoneLocation+3 ==s.length())
@@ -2167,7 +2167,7 @@ else if (timezoneLocation > 8)
21672167
}
21682168
catch (Exceptione)
21692169
{
2170-
thrownewPSQLException("postgresql.format.badtimestamp",PSQLState.UNKNOWN_STATE,s,"yyyy-MM-dd HH:mm:ss[.xxxxxx][-tz]");
2170+
thrownewPSQLException("postgresql.format.badtimestamp",PSQLState.BAD_DATETIME_FORMAT,s,"yyyy-MM-dd HH:mm:ss[.xxxxxx][-tz]");
21712171
}
21722172
timezone =0;
21732173
if (nanospos != -1)

‎src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
importorg.postgresql.util.PSQLException;
1111
importorg.postgresql.util.PSQLState;
1212

13-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.16 2003/09/08 17:30:22 barry Exp $
13+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.17 2003/09/09 10:49:16 barry Exp $
1414
* This class defines methods of the jdbc2 specification. This class extends
1515
* org.postgresql.jdbc1.AbstractJdbc1Statement which provides the jdbc1
1616
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Statement
@@ -227,7 +227,7 @@ public void setBlob(int i, Blob x) throws SQLException
227227
}
228228
catch (IOExceptionse)
229229
{
230-
thrownewPSQLException("postgresql.unusual",se);
230+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,se);
231231
}
232232
finally
233233
{
@@ -259,7 +259,7 @@ public void setCharacterStream(int i, java.io.Reader x, int length) throws SQLEx
259259
}
260260
catch (IOExceptionl_ioe)
261261
{
262-
thrownewPSQLException("postgresql.unusual",l_ioe);
262+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,l_ioe);
263263
}
264264
setString(i,newString(l_chars,0,l_charsRead));
265265
}
@@ -289,7 +289,7 @@ public void setCharacterStream(int i, java.io.Reader x, int length) throws SQLEx
289289
}
290290
catch (IOExceptionse)
291291
{
292-
thrownewPSQLException("postgresql.unusual",se);
292+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,se);
293293
}
294294
// lob is closed by the stream so don't call lob.close()
295295
setInt(i,oid);
@@ -321,7 +321,7 @@ public void setClob(int i, Clob x) throws SQLException
321321
}
322322
catch (IOExceptionse)
323323
{
324-
thrownewPSQLException("postgresql.unusual",se);
324+
thrownewPSQLException("postgresql.unusual",PSQLState.UNEXPECTED_ERROR,se);
325325
}
326326
// lob is closed by the stream so don't call lob.close()
327327
setInt(i,oid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp