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

Commit0378a26

Browse files
author
Barry Lind
committed
This set of changes applies a patch from KHO at redhat to add some SQLState
support to the jdbc driver.That patch needed some work: it assumed the sqlcode in a server message wasfixed in its position, the patch lost the ability to pass exceptions, and thepatch missed a couple of places where server errors where being received.In addition to fixing the above, I also added full support for the V3 protocolerror message syntax, I reversed the order of arguments in the PSQLExceptionconstructor to more closely follow the constructors for SQLException, I changedthe new constructors that take PSQLState to take Object for additionalparameters as the old ones did.Still todo are to add SQLState values to all existing exceptions thrown in thedriver and add support for parsing the V3 protocol format for notices. Modified Files: jdbc/build.xml jdbc/org/postgresql/Driver.java.in jdbc/org/postgresql/errors.properties jdbc/org/postgresql/core/Encoding.java jdbc/org/postgresql/core/PGStream.java jdbc/org/postgresql/core/QueryExecutor.java jdbc/org/postgresql/fastpath/Fastpath.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java jdbc/org/postgresql/util/MessageTranslator.java jdbc/org/postgresql/util/PSQLException.java
1 parente702b04 commit0378a26

13 files changed

+299
-166
lines changed

‎src/interfaces/jdbc/org/postgresql/Driver.java.in

Lines changed: 3 additions & 2 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/Attic/Driver.java.in,v 1.34 2003/07/24 00:30:38 barry Exp $
9+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/Driver.java.in,v 1.35 2003/09/08 17:30:22 barry Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -17,6 +17,7 @@ import java.sql.*;
1717
import java.util.*;
1818

1919
import org.postgresql.util.PSQLException;
20+
import org.postgresql.util.PSQLState;
2021

2122
/*
2223
* The Java SQL framework allows for multiple database drivers. Each
@@ -419,7 +420,7 @@ public class Driver implements java.sql.Driver
419420
*/
420421
public static SQLException notImplemented()
421422
{
422-
return new PSQLException("postgresql.unimplemented");
423+
return new PSQLException("postgresql.unimplemented", PSQLState.NOT_IMPLEMENTED);
423424
}
424425

425426
/**

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

Lines changed: 5 additions & 4 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/Encoding.java,v 1.11 2003/05/29 03:21:32 barry Exp $
9+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Encoding.java,v 1.12 2003/09/08 17:30:22 barry Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -19,6 +19,7 @@
1919
importjava.sql.SQLException;
2020
importjava.util.Hashtable;
2121
importorg.postgresql.util.PSQLException;
22+
importorg.postgresql.util.PSQLState;
2223

2324
publicclassEncoding
2425
{
@@ -160,7 +161,7 @@ public byte[] encode(String s) throws SQLException
160161
}
161162
catch (UnsupportedEncodingExceptione)
162163
{
163-
thrownewPSQLException("postgresql.stream.encoding",e);
164+
thrownewPSQLException("postgresql.stream.encoding",PSQLState.DATA_ERROR,e);
164165
}
165166
}
166167

@@ -185,7 +186,7 @@ public String decode(byte[] encodedString, int offset, int length) throws SQLExc
185186
}
186187
catch (UnsupportedEncodingExceptione)
187188
{
188-
thrownewPSQLException("postgresql.stream.encoding",e);
189+
thrownewPSQLException("postgresql.stream.encoding",PSQLState.DATA_ERROR,e);
189190
}
190191
}
191192

@@ -215,7 +216,7 @@ public Reader getDecodingReader(InputStream in) throws SQLException
215216
}
216217
catch (UnsupportedEncodingExceptione)
217218
{
218-
thrownewPSQLException("postgresql.res.encoding",e);
219+
thrownewPSQLException("postgresql.res.encoding",PSQLState.DATA_ERROR,e);
219220
}
220221
}
221222

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2003, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/PGStream.java,v 1.2 2003/05/29 03:21:32 barry Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/PGStream.java,v 1.3 2003/09/08 17:30:22 barry Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -20,6 +20,7 @@
2020
importjava.net.Socket;
2121
importjava.sql.*;
2222
importorg.postgresql.util.PSQLException;
23+
importorg.postgresql.util.PSQLState;
2324

2425

2526
publicclassPGStream
@@ -164,11 +165,11 @@ public int ReceiveChar() throws SQLException
164165
{
165166
c =pg_input.read();
166167
if (c <0)
167-
thrownewPSQLException("postgresql.stream.eof");
168+
thrownewPSQLException("postgresql.stream.eof",PSQLState.COMMUNICATION_ERROR);
168169
}
169170
catch (IOExceptione)
170171
{
171-
thrownewPSQLException("postgresql.stream.ioerror",e);
172+
thrownewPSQLException("postgresql.stream.ioerror",PSQLState.COMMUNICATION_ERROR,e);
172173
}
173174
returnc;
174175
}
@@ -191,13 +192,13 @@ public int ReceiveInteger(int siz) throws SQLException
191192
intb =pg_input.read();
192193

193194
if (b <0)
194-
thrownewPSQLException("postgresql.stream.eof");
195+
thrownewPSQLException("postgresql.stream.eof",PSQLState.COMMUNICATION_ERROR);
195196
n =n | (b << (8 *i)) ;
196197
}
197198
}
198199
catch (IOExceptione)
199200
{
200-
thrownewPSQLException("postgresql.stream.ioerror",e);
201+
thrownewPSQLException("postgresql.stream.ioerror",PSQLState.COMMUNICATION_ERROR,e);
201202
}
202203
returnn;
203204
}
@@ -220,13 +221,13 @@ public int ReceiveIntegerR(int siz) throws SQLException
220221
intb =pg_input.read();
221222

222223
if (b <0)
223-
thrownewPSQLException("postgresql.stream.eof");
224+
thrownewPSQLException("postgresql.stream.eof",PSQLState.COMMUNICATION_ERROR);
224225
n =b | (n <<8);
225226
}
226227
}
227228
catch (IOExceptione)
228229
{
229-
thrownewPSQLException("postgresql.stream.ioerror",e);
230+
thrownewPSQLException("postgresql.stream.ioerror",PSQLState.COMMUNICATION_ERROR,e);
230231
}
231232
returnn;
232233
}
@@ -254,7 +255,7 @@ public String ReceiveString(Encoding encoding)
254255
{
255256
intc =pg_input.read();
256257
if (c <0)
257-
thrownewPSQLException("postgresql.stream.eof");
258+
thrownewPSQLException("postgresql.stream.eof",PSQLState.COMMUNICATION_ERROR);
258259
elseif (c ==0)
259260
{
260261
rst[s] =0;
@@ -277,7 +278,7 @@ else if (c == 0)
277278
}
278279
catch (IOExceptione)
279280
{
280-
thrownewPSQLException("postgresql.stream.ioerror",e);
281+
thrownewPSQLException("postgresql.stream.ioerror",PSQLState.COMMUNICATION_ERROR,e);
281282
}
282283
returnencoding.decode(rst,0,s);
283284
}
@@ -389,13 +390,13 @@ public void Receive(byte[] b, int off, int siz) throws SQLException
389390
{
390391
intw =pg_input.read(b,off +s,siz -s);
391392
if (w <0)
392-
thrownewPSQLException("postgresql.stream.eof");
393+
thrownewPSQLException("postgresql.stream.eof",PSQLState.COMMUNICATION_ERROR);
393394
s +=w;
394395
}
395396
}
396397
catch (IOExceptione)
397398
{
398-
thrownewPSQLException("postgresql.stream.ioerror",e);
399+
thrownewPSQLException("postgresql.stream.ioerror",PSQLState.COMMUNICATION_ERROR,e);
399400
}
400401
}
401402

@@ -412,7 +413,7 @@ public void flush() throws SQLException
412413
}
413414
catch (IOExceptione)
414415
{
415-
thrownewPSQLException("postgresql.stream.flush",e);
416+
thrownewPSQLException("postgresql.stream.flush",PSQLState.COMMUNICATION_ERROR,e);
416417
}
417418
}
418419

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

Lines changed: 27 additions & 24 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.23 2003/08/11 21:18:47 barry Exp $
9+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/QueryExecutor.java,v 1.24 2003/09/08 17:30:22 barry Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -17,6 +17,7 @@
1717
importjava.sql.*;
1818
importorg.postgresql.Driver;
1919
importorg.postgresql.util.PSQLException;
20+
importorg.postgresql.util.PSQLState;
2021

2122
publicclassQueryExecutor
2223
{
@@ -108,11 +109,11 @@ private BaseResultSet execute() throws SQLException
108109
privateBaseResultSetexecuteV3()throwsSQLException
109110
{
110111

111-
StringBuffererrorMessage =null;
112+
PSQLExceptionerror =null;
112113

113114
if (pgStream ==null)
114115
{
115-
thrownewPSQLException("postgresql.con.closed");
116+
thrownewPSQLException("postgresql.con.closed",PSQLState.CONNECTION_DOES_NOT_EXIST);
116117
}
117118

118119
synchronized (pgStream)
@@ -148,11 +149,16 @@ private BaseResultSet executeV3() throws SQLException
148149
// so, append messages to a string buffer and keep processing
149150
// check at the bottom to see if we need to throw an exception
150151

151-
if (errorMessage ==null )
152-
errorMessage =newStringBuffer();
152+
intl_elen =pgStream.ReceiveIntegerR(4);
153+
StringtotalMessage =connection.getEncoding().decode(pgStream.Receive(l_elen-4));
154+
PSQLExceptionl_error =PSQLException.parseServerError(totalMessage);
155+
156+
if (error !=null) {
157+
error.setNextException(l_error);
158+
}else {
159+
error =l_error;
160+
}
153161

154-
intl_elen =pgStream.ReceiveIntegerR(4);
155-
errorMessage.append(connection.getEncoding().decode(pgStream.Receive(l_elen-4)));
156162
// keep processing
157163
break;
158164
case'I':// Empty Query
@@ -178,22 +184,20 @@ private BaseResultSet executeV3() throws SQLException
178184
case'Z':
179185
// read ReadyForQuery
180186
//TODO: use size better
181-
if (pgStream.ReceiveIntegerR(4) !=5)thrownewPSQLException("postgresql.con.setup");
187+
if (pgStream.ReceiveIntegerR(4) !=5)thrownewPSQLException("postgresql.con.setup",PSQLState.CONNECTION_UNABLE_TO_CONNECT);
182188
//TODO: handle transaction status
183189
charl_tStatus = (char)pgStream.ReceiveChar();
184190
l_endQuery =true;
185191
break;
186192
default:
187-
thrownewPSQLException("postgresql.con.type",
188-
newCharacter((char)c));
193+
thrownewPSQLException("postgresql.con.type",PSQLState.CONNECTION_FAILURE,newCharacter((char)c));
189194
}
190195

191196
}
192197

193198
// did we get an error during this query?
194-
if (errorMessage !=null )
195-
thrownewSQLException(errorMessage.toString().trim() );
196-
199+
if (error !=null )
200+
throwerror;
197201

198202
//if an existing result set was passed in reuse it, else
199203
//create a new one
@@ -216,7 +220,7 @@ private BaseResultSet executeV2() throws SQLException
216220

217221
if (pgStream ==null)
218222
{
219-
thrownewPSQLException("postgresql.con.closed");
223+
thrownewPSQLException("postgresql.con.closed",PSQLState.CONNECTION_DOES_NOT_EXIST);
220224
}
221225

222226
synchronized (pgStream)
@@ -275,8 +279,7 @@ private BaseResultSet executeV2() throws SQLException
275279
l_endQuery =true;
276280
break;
277281
default:
278-
thrownewPSQLException("postgresql.con.type",
279-
newCharacter((char)c));
282+
thrownewPSQLException("postgresql.con.type",PSQLState.CONNECTION_FAILURE,newCharacter((char)c));
280283
}
281284

282285
}
@@ -308,7 +311,7 @@ private void sendQueryV3() throws SQLException
308311
for (inti =0;i <m_binds.length ;i++ )
309312
{
310313
if (m_binds[i] ==null )
311-
thrownewPSQLException("postgresql.prep.param",newInteger(i +1));
314+
thrownewPSQLException("postgresql.prep.param",PSQLState.PARAMETER_ERROR,newInteger(i +1));
312315
}
313316
try
314317
{
@@ -349,7 +352,7 @@ private void sendQueryV2() throws SQLException
349352
for (inti =0;i <m_binds.length ;i++ )
350353
{
351354
if (m_binds[i] ==null )
352-
thrownewPSQLException("postgresql.prep.param",newInteger(i +1));
355+
thrownewPSQLException("postgresql.prep.param",PSQLState.PARAMETER_ERROR,newInteger(i +1));
353356
}
354357
try
355358
{
@@ -379,7 +382,7 @@ private void sendQueryV2() throws SQLException
379382
privatevoidreceiveTupleV3(booleanisBinary)throwsSQLException
380383
{
381384
if (fields ==null)
382-
thrownewPSQLException("postgresql.con.tuple");
385+
thrownewPSQLException("postgresql.con.tuple",PSQLState.CONNECTION_FAILURE);
383386
Objecttuple =pgStream.ReceiveTupleV3(fields.length,isBinary);
384387
if (isBinary)
385388
binaryCursor =true;
@@ -395,7 +398,7 @@ private void receiveTupleV3(boolean isBinary) throws SQLException
395398
privatevoidreceiveTupleV2(booleanisBinary)throwsSQLException
396399
{
397400
if (fields ==null)
398-
thrownewPSQLException("postgresql.con.tuple");
401+
thrownewPSQLException("postgresql.con.tuple",PSQLState.CONNECTION_FAILURE);
399402
Objecttuple =pgStream.ReceiveTupleV2(fields.length,isBinary);
400403
if (isBinary)
401404
binaryCursor =true;
@@ -429,7 +432,7 @@ private void receiveCommandStatusV3() throws SQLException
429432
}
430433
catch (NumberFormatExceptionnfe)
431434
{
432-
thrownewPSQLException("postgresql.con.fathom",status);
435+
thrownewPSQLException("postgresql.con.fathom",PSQLState.CONNECTION_FAILURE,status);
433436
}
434437
}
435438
/*
@@ -455,7 +458,7 @@ private void receiveCommandStatusV2() throws SQLException
455458
}
456459
catch (NumberFormatExceptionnfe)
457460
{
458-
thrownewPSQLException("postgresql.con.fathom",status);
461+
thrownewPSQLException("postgresql.con.fathom",PSQLState.CONNECTION_FAILURE,status);
459462
}
460463
}
461464

@@ -467,7 +470,7 @@ private void receiveFieldsV3() throws SQLException
467470
//TODO: use the msgSize
468471
//TODO: use the tableOid, and tablePosition
469472
if (fields !=null)
470-
thrownewPSQLException("postgresql.con.multres");
473+
thrownewPSQLException("postgresql.con.multres",PSQLState.CONNECTION_FAILURE);
471474
intl_msgSize =pgStream.ReceiveIntegerR(4);
472475
intsize =pgStream.ReceiveIntegerR(2);
473476
fields =newField[size];
@@ -491,7 +494,7 @@ private void receiveFieldsV3() throws SQLException
491494
privatevoidreceiveFieldsV2()throwsSQLException
492495
{
493496
if (fields !=null)
494-
thrownewPSQLException("postgresql.con.multres");
497+
thrownewPSQLException("postgresql.con.multres",PSQLState.CONNECTION_FAILURE);
495498

496499
intsize =pgStream.ReceiveIntegerR(2);
497500
fields =newField[size];

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ postgresql.con.invalidchar:Invalid character data was found. This is most likel
99
postgresql.con.closed:Connection is closed. Operation is not permitted.
1010
postgresql.con.creobj:Failed to create object for {0} {1}
1111
postgresql.con.failed:The connection attempt failed because {0}
12+
postgresql.con.failed.bad.encoding:The connection attempt failed trying to get the server encoding
13+
postgresql.con.failed.bad.autocommit:The connection attempt failed trying to get the autocommit status
1214
postgresql.con.fathom:Unable to fathom update count {0}
1315
postgresql.con.garbled:Garbled data received.
1416
postgresql.con.ioerror:An IO erro occured while sending to the backend - {0}
@@ -29,6 +31,11 @@ postgresql.con.isolevel:Transaction isolation level {0} is not supported.
2931
postgresql.con.tuple:Tuple received before MetaData.
3032
postgresql.con.type:Unknown Response Type {0}
3133
postgresql.con.user:The user property is missing. It is mandatory.
34+
postgresql.error.detail:Detail: {0}
35+
postgresql.error.hint:Hint: {0}
36+
postgresql.error.position:Position: {0}
37+
postgresql.error.where:Where: {0}
38+
postgresql.error.location:Location: {0}
3239
postgresql.fp.error:FastPath call returned {0}
3340
postgresql.fp.expint:Fastpath call {0} - No result was returned and we expected an integer.
3441
postgresql.fp.protocol:FastPath protocol error: {0}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp