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

Commit 4c63b25

Browse files
author
Peter Mount
committed
Internationalisation of error messages
1 parent c2f0d56 commit 4c63b25

27 files changed

+198
-132
lines changed

src/interfaces/jdbc/postgresql/Connection.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import postgresql.util.*;
1111

1212
/**
13-
* $Id: Connection.java,v 1.16 1999/05/17 22:43:23 peter Exp $
13+
* $Id: Connection.java,v 1.17 1999/05/18 23:17:15 peter Exp $
1414
*
1515
* This abstract class is used by postgresql.Driver to open either the JDBC1 or
1616
* JDBC2 versions of the Connection class.
@@ -95,9 +95,9 @@ protected void openConnection(String host, int port, Properties info, String dat
9595
// This occasionally occurs when the client uses the properties version
9696
// of getConnection(), and is a common question on the email lists
9797
if(info.getProperty("user")==null)
98-
throw new SQLException("The user property is missing. It is mandatory.");
98+
throw new PSQLException("postgresql.con.user");
9999
if(info.getProperty("password")==null)
100-
throw new SQLException("The password property is missing. It is mandatory.");
100+
throw new PSQLException("postgresql.con.pass");
101101

102102
this_driver = d;
103103
this_url = new String(url);
@@ -116,9 +116,9 @@ protected void openConnection(String host, int port, Properties info, String dat
116116
// Added by Peter Mount <peter@retep.org.uk>
117117
// ConnectException is thrown when the connection cannot be made.
118118
// we trap this an return a more meaningful message for the end user
119-
throw new SQLException ("Connection refused. Check that the hostname and port is correct, and that the postmaster is running with the -i flag, which enables TCP/IP networking.");
119+
throw new PSQLException ("postgresql.con.refused");
120120
} catch (IOException e) {
121-
throw new SQLException ("Connection failed: " + e.toString());
121+
throw new PSQLException ("postgresql.con.failed",e);
122122
}
123123

124124
// Now we need to construct and send a startup packet
@@ -173,11 +173,11 @@ protected void openConnection(String host, int port, Properties info, String dat
173173

174174
case AUTH_REQ_KRB4:
175175
DriverManager.println("postgresql: KRB4");
176-
throw new SQLException("Kerberos 4 not supported");
176+
throw new PSQLException("postgresql.con.kerb4");
177177

178178
case AUTH_REQ_KRB5:
179179
DriverManager.println("postgresql: KRB5");
180-
throw new SQLException("Kerberos 5 not supported");
180+
throw new PSQLException("postgresql.con.kerb5");
181181

182182
case AUTH_REQ_PASSWORD:
183183
DriverManager.println("postgresql: PASSWORD");
@@ -197,17 +197,17 @@ protected void openConnection(String host, int port, Properties info, String dat
197197
break;
198198

199199
default:
200-
throw new SQLException("Authentication type "+areq+" not supported. Check that you have configured the pg_hba.conf file to include the client's IP address or Subnet, and is using a supported authentication scheme.");
200+
throw new PSQLException("postgresql.con.auth",new Integer(areq));
201201
}
202202
break;
203203

204204
default:
205-
throw new SQLException("error getting authentication request");
205+
throw new PSQLException("postgresql.con.authfail");
206206
}
207207
} while(areq != AUTH_REQ_OK);
208208

209209
} catch (IOException e) {
210-
throw new SQLException("Connection failed: " + e.toString());
210+
throw new PSQLException("postgresql.con.failed",e);
211211
}
212212

213213
// Originally we issued a SHOW DATESTYLE statement to find the databases default
@@ -290,7 +290,7 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
290290
SQLException final_error = null;
291291

292292
if (sql.length() > 8192)
293-
throw new SQLException("SQL Statement too long: " + sql);
293+
throw new PSQLException("postgresql.con.toolong",sql);
294294
try
295295
{
296296
pg_stream.SendChar('Q');
@@ -299,7 +299,7 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
299299
pg_stream.SendChar(0);
300300
pg_stream.flush();
301301
} catch (IOException e) {
302-
throw new SQLException("I/O Error: " + e.toString());
302+
throw new PSQLException("postgresql.con.ioerror",e);
303303
}
304304

305305
while (!hfr || fqp > 0)
@@ -316,7 +316,7 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
316316
break;
317317
case 'B': // Binary Data Transfer
318318
if (fields == null)
319-
throw new SQLException("Tuple received before MetaData");
319+
throw new PSQLException("postgresql.con.tuple");
320320
tup = pg_stream.ReceiveTuple(fields.length, true);
321321
// This implements Statement.setMaxRows()
322322
if(maxrows==0 || tuples.size()<maxrows)
@@ -330,7 +330,7 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
330330
try {
331331
update_count = Integer.parseInt(recv_status.substring(1+recv_status.lastIndexOf(' ')));
332332
} catch(NumberFormatException nfe) {
333-
throw new SQLException("Unable to fathom update count \""+recv_status+"\"");
333+
throw new PSQLException("postgresql.con.fathom",recv_status);
334334
}
335335
}
336336
if (fields != null)
@@ -344,14 +344,14 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
344344
pg_stream.SendChar(0);
345345
pg_stream.flush();
346346
} catch (IOException e) {
347-
throw new SQLException("I/O Error: " + e.toString());
347+
throw new PSQLException("postgresql.con.ioerror",e);
348348
}
349349
fqp++;
350350
}
351351
break;
352352
case 'D': // Text Data Transfer
353353
if (fields == null)
354-
throw new SQLException("Tuple received before MetaData");
354+
throw new PSQLException("postgresql.con.tuple");
355355
tup = pg_stream.ReceiveTuple(fields.length, false);
356356
// This implements Statement.setMaxRows()
357357
if(maxrows==0 || tuples.size()<maxrows)
@@ -366,7 +366,7 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
366366
int t = pg_stream.ReceiveChar();
367367

368368
if (t != 0)
369-
throw new SQLException("Garbled Data");
369+
throw new PSQLException("postgresql.con.garbled");
370370
if (fqp > 0)
371371
fqp--;
372372
if (fqp == 0)
@@ -380,11 +380,11 @@ public java.sql.ResultSet ExecSQL(String sql) throws SQLException
380380
break;
381381
case 'T': // MetaData Field Description
382382
if (fields != null)
383-
throw new SQLException("Cannot handle multiple result groups");
383+
throw new PSQLException("postgresql.con.multres");
384384
fields = ReceiveFields();
385385
break;
386386
default:
387-
throw new SQLException("Unknown Response Type: " + (char)c);
387+
throw new PSQLException("postgresql.con.type",new Character((char)c));
388388
}
389389
}
390390
if (final_error != null)
@@ -587,7 +587,7 @@ public Object getObject(String type,String value) throws SQLException
587587
sx.fillInStackTrace();
588588
throw sx;
589589
} catch(Exception ex) {
590-
throw new SQLException("Failed to create object for "+type+": "+ex);
590+
throw new PSQLException("postgresql.con.creobj",type,ex);
591591
}
592592

593593
// should never be reached
@@ -622,14 +622,14 @@ public int putObject(Object o) throws SQLException
622622
return ((Serialize)x).store(o);
623623

624624
// Thow an exception because the type is unknown
625-
throw new SQLException("The object could not be stored. Check that any tables required have already been created in the database.");
625+
throw new PSQLException("postgresql.con.strobj");
626626

627627
} catch(SQLException sx) {
628628
// rethrow the exception. Done because we capture any others next
629629
sx.fillInStackTrace();
630630
throw sx;
631631
} catch(Exception ex) {
632-
throw new SQLException("Failed to store object: "+ex);
632+
throw new PSQLException("postgresql.con.strobjex",ex);
633633
}
634634
}
635635

src/interfaces/jdbc/postgresql/Driver.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
import java.sql.*;
44
import java.util.*;
55

6-
// You will find some mentions to a PSQLException class. This was intended
7-
// to allow internationalisation of error messages. However, this is not
8-
// working quite to plan, so the class exists in the source, but it's not
9-
// quite implemented yet. Peter May 17 1999.
10-
//
116
import postgresql.util.PSQLException;
127

138
/**
@@ -109,10 +104,8 @@ public java.sql.Connection connect(String url, Properties info) throws SQLExcept
109104
return (java.sql.Connection)con;
110105
} catch(ClassNotFoundException ex) {
111106
throw new PSQLException("postgresql.jvm.version",ex);
112-
//throw new SQLException("The postgresql.jar file does not contain the correct JDBC classes for this JVM. Try rebuilding.\nException thrown was "+ex.toString());
113107
} catch(Exception ex2) {
114108
throw new PSQLException("postgresql.unusual",ex2);
115-
//throw new SQLException("Something unusual has occured to cause the driver to fail. Please report this exception: "+ex2.toString());
116109
}
117110
// The old call - remove before posting
118111
//return new Connection (host(), port(), props, database(), url, this);
@@ -356,7 +349,6 @@ public String property(String name)
356349
public static SQLException notImplemented()
357350
{
358351
return new PSQLException("postgresql.unimplemented");
359-
//return new SQLException("This method is not yet implemented.");
360352
}
361353
}
362354

src/interfaces/jdbc/postgresql/Field.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.sql.*;
55
import java.util.*;
66
import postgresql.*;
7+
import postgresql.util.*;
78

89
/**
910
* postgresql.Field is a class used to describe fields in a PostgreSQL
@@ -62,7 +63,7 @@ public int getSQLType() throws SQLException
6263
if(type_name==null) {
6364
ResultSet result = (postgresql.ResultSet)conn.ExecSQL("select typname from pg_type where oid = " + oid);
6465
if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
65-
throw new SQLException("Unexpected return from query for type");
66+
throw new PSQLException("postgresql.unexpected");
6667
result.next();
6768
type_name = result.getString(1);
6869
conn.fieldCache.put(new Integer(oid),type_name);

src/interfaces/jdbc/postgresql/PG_Stream.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.*;
77
import java.sql.*;
88
import postgresql.*;
9+
import postgresql.util.*;
910

1011
/**
1112
* @version 1.0 15-APR-1997
@@ -22,15 +23,6 @@ public class PG_Stream
2223
private InputStream pg_input;
2324
private BufferedOutputStream pg_output;
2425

25-
// This is the error message returned when an EOF occurs
26-
private static final String EOF_MSG = "The backend has broken the connection. Possibly the action you have attempted has caused it to close.";
27-
28-
// This is the error message returned when an IOException occurs
29-
private static final String IOE_MSG = "IOError while reading from backend: ";
30-
31-
// This is the error message returned when flushing the stream.
32-
private static final String FLUSH_MSG = "Error flushing output: ";
33-
3426
/**
3527
* Constructor: Connect to the PostgreSQL back end and return
3628
* a stream connection.
@@ -178,9 +170,9 @@ public int ReceiveChar() throws SQLException
178170
try
179171
{
180172
c = pg_input.read();
181-
if (c < 0) throw new IOException(EOF_MSG);
173+
if (c < 0) throw new PSQLException("postgresql.stream.eof");
182174
} catch (IOException e) {
183-
throw new SQLException(IOE_MSG + e.toString());
175+
throw new PSQLException("postgresql.stream.ioerror",e);
184176
}
185177
return c;
186178
}
@@ -203,11 +195,11 @@ public int ReceiveInteger(int siz) throws SQLException
203195
int b = pg_input.read();
204196

205197
if (b < 0)
206-
throw new IOException(EOF_MSG);
198+
throw new PSQLException("postgresql.stream.eof");
207199
n = n | (b << (8 * i)) ;
208200
}
209201
} catch (IOException e) {
210-
throw new SQLException(IOE_MSG + e.toString());
202+
throw new PSQLException("postgresql.stream.ioerror",e);
211203
}
212204
return n;
213205
}
@@ -230,11 +222,11 @@ public int ReceiveIntegerR(int siz) throws SQLException
230222
int b = pg_input.read();
231223

232224
if (b < 0)
233-
throw new IOException(EOF_MSG);
225+
throw new PSQLException("postgresql.stream.eof");
234226
n = b | (n << 8);
235227
}
236228
} catch (IOException e) {
237-
throw new SQLException(IOE_MSG + e.toString());
229+
throw new PSQLException("postgresql.stream.ioerror",e);
238230
}
239231
return n;
240232
}
@@ -259,16 +251,16 @@ public String ReceiveString(int maxsiz) throws SQLException
259251
{
260252
int c = pg_input.read();
261253
if (c < 0)
262-
throw new IOException(EOF_MSG);
254+
throw new PSQLException("postgresql.stream.eof");
263255
else if (c == 0)
264256
break;
265257
else
266258
rst[s++] = (byte)c;
267259
}
268260
if (s >= maxsiz)
269-
throw new IOException("Too Much Data");
261+
throw new PSQLException("postgresql.stream.toomuch");
270262
} catch (IOException e) {
271-
throw new SQLException(IOE_MSG + e.toString());
263+
throw new PSQLException("postgresql.stream.ioerror",e);
272264
}
273265
String v = new String(rst, 0, s);
274266
return v;
@@ -349,11 +341,11 @@ public void Receive(byte[] b,int off,int siz) throws SQLException
349341
{
350342
int w = pg_input.read(b, off+s, siz - s);
351343
if (w < 0)
352-
throw new IOException(EOF_MSG);
344+
throw new PSQLException("postgresql.stream.eof");
353345
s += w;
354346
}
355347
} catch (IOException e) {
356-
throw new SQLException(IOE_MSG + e.toString());
348+
throw new PSQLException("postgresql.stream.ioerror",e);
357349
}
358350
}
359351

@@ -367,7 +359,7 @@ public void flush() throws SQLException
367359
try {
368360
pg_output.flush();
369361
} catch (IOException e) {
370-
throw new SQLException(FLUSH_MSG + e.toString());
362+
throw new PSQLException("postgresql.stream.flush",e);
371363
}
372364
}
373365

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,67 @@
11
# This is the default errors
2+
postgresql.con.auth:The authentication type {1} is not supported. Check that you have configured the pg_hba.conf file to include the client's IP address or Subnet, and that it is using an authentication scheme supported by the driver.
3+
postgresql.con.authfail:An error occured while getting the authentication request.
4+
postgresql.con.call:Callable Statements are not supported at this time.
5+
postgresql.con.creobj:Failed to create object for {1} {2}
6+
postgresql.con.failed:The connection attempt failed because {1}
7+
postgresql.con.fathom:Unable to fathom update count {1}
8+
postgresql.con.garbled:Garbled data received.
9+
postgresql.con.ioerror:An IO erro occured while sending to the backend - {1}
10+
postgresql.con.kerb4:Kerberos 4 authentication is not supported by this driver.
11+
postgresql.con.kerb5:Kerberos 5 authentication is not supported by this driver.
12+
postgresql.con.multres:Cannot handle multiple result groups.
13+
postgresql.con.pass:The password property is missing. It is mandatory.
14+
postgresql.con.refused:Connection refused. Check that the hostname and port is correct, and that the postmaster is running with the -i flag, which enables TCP/IP networking.
15+
postgresql.con.strobj:The object could not be stored. Check that any tables required have already been created in the database.
16+
postgresql.con.strobjex:Failed to store object - {1}
17+
postgresql.con.toolong:The SQL Statement is too long - {1}
18+
postgresql.con.tuple:Tuple received before MetaData.
19+
postgresql.con.type:Unknown Response Type {1}
20+
postgresql.con.user:The user property is missing. It is mandatory.
21+
postgresql.fp.error:FastPath call returned {1}
22+
postgresql.fp.expint:Fastpath call {1} - No result was returned and we expected an integer.
23+
postgresql.fp.protocol:FastPath protocol error: {1}
24+
postgresql.fp.send:Failed to send fastpath call {1} {2}
25+
postgresql.fp.unknown:The fastpath function {1} is unknown.
26+
postgresql.geo.box:Conversion of box failed - {1}
27+
postgresql.geo.circle:Conversion of circle failed - {1}
28+
postgresql.geo.line:Conversion of line failed - {1}
29+
postgresql.geo.lseg:Conversion of lseg failed - {1}
30+
postgresql.geo.path:Cannot tell if path is open or closed.
31+
postgresql.geo.point:Conversion of point failed - {1}
232
postgresql.jvm.version:The postgresql.jar file does not contain the correct JDBC classes for this JVM. Try rebuilding.\nException thrown was {1}
33+
postgresql.lo.init:failed to initialise LargeObject API
34+
postgresql.money:conversion of money failed - {1}.
35+
postgresql.prep.is:InputStream as parameter not supported
36+
postgresql.prep.param:No value specified for parameter {1}.
37+
postgresql.prep.range:Parameter index out of range.
38+
postgresql.prep.type:Unknown Types value.
39+
postgresql.res.badbigdec:Bad BigDecimal {1}
40+
postgresql.res.badbyte:Bad Byte {1}
41+
postgresql.res.baddate:Bad Date Format at {1} in {2}
42+
postgresql.res.baddouble:Bad Double {1}
43+
postgresql.res.badfloat:Bad Float {1}
44+
postgresql.res.badint:Bad Integer {1}
45+
postgresql.res.badlong:Bad Long {1}
46+
postgresql.res.badshort:Bad Short {1}
47+
postgresql.res.badtime:Bad Time {1}
48+
postgresql.res.badtimestamp:Bad Timestamp Format at {1} in {2}
49+
postgresql.res.colname:The column name {1} not found.
50+
postgresql.res.colrange:The column index is out of range.
51+
postgresql.serial.interface:You cannot serialize an interface.
52+
postgresql.serial.namelength:Class & Package name length cannot be longer than 32 characters. {1} is {2} characters.
53+
postgresql.serial.noclass:No class found for {1}.
54+
postgresql.serial.table:The table for {1} is not in the database. Contact the DBA, as the database is in an inconsistent state.
55+
postgresql.serial.underscore:Class names may not have _ in them. You supplied {1}.
56+
postgresql.stat.batch.empty:The batch is empty. There is nothing to execute.
57+
postgresql.stat.batch.error:Batch entry {1} {2} was aborted.
58+
postgresql.stat.maxfieldsize:An attempt to setMaxFieldSize() failed - compile time default in force.
59+
postgresql.stat.noresult:No results were returned by the query.
60+
postgresql.stat.result:A result was returned by the statement, when none was expected.
61+
postgresql.stream.eof:The backend has broken the connection. Possibly the action you have attempted has caused it to close.
62+
postgresql.stream.flush:An I/O error has occured while flushing the output - {1}
63+
postgresql.stream.ioerror:An I/O error occured while reading from backend - {1}
64+
postgresql.stream.toomuch:Too much data was received.
365
postgresql.unusual:Something unusual has occured to cause the driver to fail. Please report this exception: {1}
466
postgresql.unimplemented:This method is not yet implemented.
67+
postgresql.unexpected:An unexpected result was returned by a query.

0 commit comments

Comments
 (0)