Internationalisation of error messages

This commit is contained in:
Peter Mount 1999-05-18 23:17:46 +00:00
parent c2f0d565f3
commit 4c63b257fd
27 changed files with 198 additions and 132 deletions

View File

@ -10,7 +10,7 @@ import postgresql.largeobject.*;
import postgresql.util.*;
/**
* $Id: Connection.java,v 1.16 1999/05/17 22:43:23 peter Exp $
* $Id: Connection.java,v 1.17 1999/05/18 23:17:15 peter Exp $
*
* This abstract class is used by postgresql.Driver to open either the JDBC1 or
* JDBC2 versions of the Connection class.
@ -95,9 +95,9 @@ public abstract class Connection
// This occasionally occurs when the client uses the properties version
// of getConnection(), and is a common question on the email lists
if(info.getProperty("user")==null)
throw new SQLException("The user property is missing. It is mandatory.");
throw new PSQLException("postgresql.con.user");
if(info.getProperty("password")==null)
throw new SQLException("The password property is missing. It is mandatory.");
throw new PSQLException("postgresql.con.pass");
this_driver = d;
this_url = new String(url);
@ -116,9 +116,9 @@ public abstract class Connection
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
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.");
throw new PSQLException ("postgresql.con.refused");
} catch (IOException e) {
throw new SQLException ("Connection failed: " + e.toString());
throw new PSQLException ("postgresql.con.failed",e);
}
// Now we need to construct and send a startup packet
@ -173,11 +173,11 @@ public abstract class Connection
case AUTH_REQ_KRB4:
DriverManager.println("postgresql: KRB4");
throw new SQLException("Kerberos 4 not supported");
throw new PSQLException("postgresql.con.kerb4");
case AUTH_REQ_KRB5:
DriverManager.println("postgresql: KRB5");
throw new SQLException("Kerberos 5 not supported");
throw new PSQLException("postgresql.con.kerb5");
case AUTH_REQ_PASSWORD:
DriverManager.println("postgresql: PASSWORD");
@ -197,17 +197,17 @@ public abstract class Connection
break;
default:
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.");
throw new PSQLException("postgresql.con.auth",new Integer(areq));
}
break;
default:
throw new SQLException("error getting authentication request");
throw new PSQLException("postgresql.con.authfail");
}
} while(areq != AUTH_REQ_OK);
} catch (IOException e) {
throw new SQLException("Connection failed: " + e.toString());
throw new PSQLException("postgresql.con.failed",e);
}
// Originally we issued a SHOW DATESTYLE statement to find the databases default
@ -290,7 +290,7 @@ public abstract class Connection
SQLException final_error = null;
if (sql.length() > 8192)
throw new SQLException("SQL Statement too long: " + sql);
throw new PSQLException("postgresql.con.toolong",sql);
try
{
pg_stream.SendChar('Q');
@ -299,7 +299,7 @@ public abstract class Connection
pg_stream.SendChar(0);
pg_stream.flush();
} catch (IOException e) {
throw new SQLException("I/O Error: " + e.toString());
throw new PSQLException("postgresql.con.ioerror",e);
}
while (!hfr || fqp > 0)
@ -316,7 +316,7 @@ public abstract class Connection
break;
case 'B': // Binary Data Transfer
if (fields == null)
throw new SQLException("Tuple received before MetaData");
throw new PSQLException("postgresql.con.tuple");
tup = pg_stream.ReceiveTuple(fields.length, true);
// This implements Statement.setMaxRows()
if(maxrows==0 || tuples.size()<maxrows)
@ -330,7 +330,7 @@ public abstract class Connection
try {
update_count = Integer.parseInt(recv_status.substring(1+recv_status.lastIndexOf(' ')));
} catch(NumberFormatException nfe) {
throw new SQLException("Unable to fathom update count \""+recv_status+"\"");
throw new PSQLException("postgresql.con.fathom",recv_status);
}
}
if (fields != null)
@ -344,14 +344,14 @@ public abstract class Connection
pg_stream.SendChar(0);
pg_stream.flush();
} catch (IOException e) {
throw new SQLException("I/O Error: " + e.toString());
throw new PSQLException("postgresql.con.ioerror",e);
}
fqp++;
}
break;
case 'D': // Text Data Transfer
if (fields == null)
throw new SQLException("Tuple received before MetaData");
throw new PSQLException("postgresql.con.tuple");
tup = pg_stream.ReceiveTuple(fields.length, false);
// This implements Statement.setMaxRows()
if(maxrows==0 || tuples.size()<maxrows)
@ -366,7 +366,7 @@ public abstract class Connection
int t = pg_stream.ReceiveChar();
if (t != 0)
throw new SQLException("Garbled Data");
throw new PSQLException("postgresql.con.garbled");
if (fqp > 0)
fqp--;
if (fqp == 0)
@ -380,11 +380,11 @@ public abstract class Connection
break;
case 'T': // MetaData Field Description
if (fields != null)
throw new SQLException("Cannot handle multiple result groups");
throw new PSQLException("postgresql.con.multres");
fields = ReceiveFields();
break;
default:
throw new SQLException("Unknown Response Type: " + (char)c);
throw new PSQLException("postgresql.con.type",new Character((char)c));
}
}
if (final_error != null)
@ -587,7 +587,7 @@ public abstract class Connection
sx.fillInStackTrace();
throw sx;
} catch(Exception ex) {
throw new SQLException("Failed to create object for "+type+": "+ex);
throw new PSQLException("postgresql.con.creobj",type,ex);
}
// should never be reached
@ -622,14 +622,14 @@ public abstract class Connection
return ((Serialize)x).store(o);
// Thow an exception because the type is unknown
throw new SQLException("The object could not be stored. Check that any tables required have already been created in the database.");
throw new PSQLException("postgresql.con.strobj");
} catch(SQLException sx) {
// rethrow the exception. Done because we capture any others next
sx.fillInStackTrace();
throw sx;
} catch(Exception ex) {
throw new SQLException("Failed to store object: "+ex);
throw new PSQLException("postgresql.con.strobjex",ex);
}
}

View File

@ -3,11 +3,6 @@ package postgresql;
import java.sql.*;
import java.util.*;
// You will find some mentions to a PSQLException class. This was intended
// to allow internationalisation of error messages. However, this is not
// working quite to plan, so the class exists in the source, but it's not
// quite implemented yet. Peter May 17 1999.
//
import postgresql.util.PSQLException;
/**
@ -109,10 +104,8 @@ public class Driver implements java.sql.Driver
return (java.sql.Connection)con;
} catch(ClassNotFoundException ex) {
throw new PSQLException("postgresql.jvm.version",ex);
//throw new SQLException("The postgresql.jar file does not contain the correct JDBC classes for this JVM. Try rebuilding.\nException thrown was "+ex.toString());
} catch(Exception ex2) {
throw new PSQLException("postgresql.unusual",ex2);
//throw new SQLException("Something unusual has occured to cause the driver to fail. Please report this exception: "+ex2.toString());
}
// The old call - remove before posting
//return new Connection (host(), port(), props, database(), url, this);
@ -356,7 +349,6 @@ public class Driver implements java.sql.Driver
public static SQLException notImplemented()
{
return new PSQLException("postgresql.unimplemented");
//return new SQLException("This method is not yet implemented.");
}
}

View File

@ -4,6 +4,7 @@ import java.lang.*;
import java.sql.*;
import java.util.*;
import postgresql.*;
import postgresql.util.*;
/**
* postgresql.Field is a class used to describe fields in a PostgreSQL
@ -62,7 +63,7 @@ public class Field
if(type_name==null) {
ResultSet result = (postgresql.ResultSet)conn.ExecSQL("select typname from pg_type where oid = " + oid);
if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
throw new SQLException("Unexpected return from query for type");
throw new PSQLException("postgresql.unexpected");
result.next();
type_name = result.getString(1);
conn.fieldCache.put(new Integer(oid),type_name);

View File

@ -6,6 +6,7 @@ import java.net.*;
import java.util.*;
import java.sql.*;
import postgresql.*;
import postgresql.util.*;
/**
* @version 1.0 15-APR-1997
@ -22,15 +23,6 @@ public class PG_Stream
private InputStream pg_input;
private BufferedOutputStream pg_output;
// This is the error message returned when an EOF occurs
private static final String EOF_MSG = "The backend has broken the connection. Possibly the action you have attempted has caused it to close.";
// This is the error message returned when an IOException occurs
private static final String IOE_MSG = "IOError while reading from backend: ";
// This is the error message returned when flushing the stream.
private static final String FLUSH_MSG = "Error flushing output: ";
/**
* Constructor: Connect to the PostgreSQL back end and return
* a stream connection.
@ -178,9 +170,9 @@ public class PG_Stream
try
{
c = pg_input.read();
if (c < 0) throw new IOException(EOF_MSG);
if (c < 0) throw new PSQLException("postgresql.stream.eof");
} catch (IOException e) {
throw new SQLException(IOE_MSG + e.toString());
throw new PSQLException("postgresql.stream.ioerror",e);
}
return c;
}
@ -203,11 +195,11 @@ public class PG_Stream
int b = pg_input.read();
if (b < 0)
throw new IOException(EOF_MSG);
throw new PSQLException("postgresql.stream.eof");
n = n | (b << (8 * i)) ;
}
} catch (IOException e) {
throw new SQLException(IOE_MSG + e.toString());
throw new PSQLException("postgresql.stream.ioerror",e);
}
return n;
}
@ -230,11 +222,11 @@ public class PG_Stream
int b = pg_input.read();
if (b < 0)
throw new IOException(EOF_MSG);
throw new PSQLException("postgresql.stream.eof");
n = b | (n << 8);
}
} catch (IOException e) {
throw new SQLException(IOE_MSG + e.toString());
throw new PSQLException("postgresql.stream.ioerror",e);
}
return n;
}
@ -259,16 +251,16 @@ public class PG_Stream
{
int c = pg_input.read();
if (c < 0)
throw new IOException(EOF_MSG);
throw new PSQLException("postgresql.stream.eof");
else if (c == 0)
break;
else
rst[s++] = (byte)c;
}
if (s >= maxsiz)
throw new IOException("Too Much Data");
throw new PSQLException("postgresql.stream.toomuch");
} catch (IOException e) {
throw new SQLException(IOE_MSG + e.toString());
throw new PSQLException("postgresql.stream.ioerror",e);
}
String v = new String(rst, 0, s);
return v;
@ -349,11 +341,11 @@ public class PG_Stream
{
int w = pg_input.read(b, off+s, siz - s);
if (w < 0)
throw new IOException(EOF_MSG);
throw new PSQLException("postgresql.stream.eof");
s += w;
}
} catch (IOException e) {
throw new SQLException(IOE_MSG + e.toString());
throw new PSQLException("postgresql.stream.ioerror",e);
}
}
@ -367,7 +359,7 @@ public class PG_Stream
try {
pg_output.flush();
} catch (IOException e) {
throw new SQLException(FLUSH_MSG + e.toString());
throw new PSQLException("postgresql.stream.flush",e);
}
}

View File

@ -1,4 +1,67 @@
# This is the default errors
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.
postgresql.con.authfail:An error occured while getting the authentication request.
postgresql.con.call:Callable Statements are not supported at this time.
postgresql.con.creobj:Failed to create object for {1} {2}
postgresql.con.failed:The connection attempt failed because {1}
postgresql.con.fathom:Unable to fathom update count {1}
postgresql.con.garbled:Garbled data received.
postgresql.con.ioerror:An IO erro occured while sending to the backend - {1}
postgresql.con.kerb4:Kerberos 4 authentication is not supported by this driver.
postgresql.con.kerb5:Kerberos 5 authentication is not supported by this driver.
postgresql.con.multres:Cannot handle multiple result groups.
postgresql.con.pass:The password property is missing. It is mandatory.
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.
postgresql.con.strobj:The object could not be stored. Check that any tables required have already been created in the database.
postgresql.con.strobjex:Failed to store object - {1}
postgresql.con.toolong:The SQL Statement is too long - {1}
postgresql.con.tuple:Tuple received before MetaData.
postgresql.con.type:Unknown Response Type {1}
postgresql.con.user:The user property is missing. It is mandatory.
postgresql.fp.error:FastPath call returned {1}
postgresql.fp.expint:Fastpath call {1} - No result was returned and we expected an integer.
postgresql.fp.protocol:FastPath protocol error: {1}
postgresql.fp.send:Failed to send fastpath call {1} {2}
postgresql.fp.unknown:The fastpath function {1} is unknown.
postgresql.geo.box:Conversion of box failed - {1}
postgresql.geo.circle:Conversion of circle failed - {1}
postgresql.geo.line:Conversion of line failed - {1}
postgresql.geo.lseg:Conversion of lseg failed - {1}
postgresql.geo.path:Cannot tell if path is open or closed.
postgresql.geo.point:Conversion of point failed - {1}
postgresql.jvm.version:The postgresql.jar file does not contain the correct JDBC classes for this JVM. Try rebuilding.\nException thrown was {1}
postgresql.lo.init:failed to initialise LargeObject API
postgresql.money:conversion of money failed - {1}.
postgresql.prep.is:InputStream as parameter not supported
postgresql.prep.param:No value specified for parameter {1}.
postgresql.prep.range:Parameter index out of range.
postgresql.prep.type:Unknown Types value.
postgresql.res.badbigdec:Bad BigDecimal {1}
postgresql.res.badbyte:Bad Byte {1}
postgresql.res.baddate:Bad Date Format at {1} in {2}
postgresql.res.baddouble:Bad Double {1}
postgresql.res.badfloat:Bad Float {1}
postgresql.res.badint:Bad Integer {1}
postgresql.res.badlong:Bad Long {1}
postgresql.res.badshort:Bad Short {1}
postgresql.res.badtime:Bad Time {1}
postgresql.res.badtimestamp:Bad Timestamp Format at {1} in {2}
postgresql.res.colname:The column name {1} not found.
postgresql.res.colrange:The column index is out of range.
postgresql.serial.interface:You cannot serialize an interface.
postgresql.serial.namelength:Class & Package name length cannot be longer than 32 characters. {1} is {2} characters.
postgresql.serial.noclass:No class found for {1}.
postgresql.serial.table:The table for {1} is not in the database. Contact the DBA, as the database is in an inconsistent state.
postgresql.serial.underscore:Class names may not have _ in them. You supplied {1}.
postgresql.stat.batch.empty:The batch is empty. There is nothing to execute.
postgresql.stat.batch.error:Batch entry {1} {2} was aborted.
postgresql.stat.maxfieldsize:An attempt to setMaxFieldSize() failed - compile time default in force.
postgresql.stat.noresult:No results were returned by the query.
postgresql.stat.result:A result was returned by the statement, when none was expected.
postgresql.stream.eof:The backend has broken the connection. Possibly the action you have attempted has caused it to close.
postgresql.stream.flush:An I/O error has occured while flushing the output - {1}
postgresql.stream.ioerror:An I/O error occured while reading from backend - {1}
postgresql.stream.toomuch:Too much data was received.
postgresql.unusual:Something unusual has occured to cause the driver to fail. Please report this exception: {1}
postgresql.unimplemented:This method is not yet implemented.
postgresql.unexpected:An unexpected result was returned by a query.

View File

@ -93,7 +93,7 @@ public class Fastpath
stream.flush();
} catch(IOException ioe) {
throw new SQLException("Failed to send fastpath call "+fnid+"\n"+ioe);
throw new PSQLException("postgresql.fp.send",new Integer(fnid),ioe);
}
// Now handle the result
@ -138,7 +138,7 @@ public class Fastpath
//------------------------------
// Error message returned
case 'E':
throw new SQLException("Fastpath: "+stream.ReceiveString(4096));
throw new PSQLException("postgresql.fp.error",stream.ReceiveString(4096));
//------------------------------
// Notice from backend
@ -156,7 +156,7 @@ public class Fastpath
return result;
default:
throw new SQLException("Fastpath: protocol error. Got '"+((char)in)+"'");
throw new PSQLException("postgresql.fp.protocol",new Character((char)in));
}
}
}
@ -199,7 +199,7 @@ public class Fastpath
{
Integer i = (Integer)fastpath(name,true,args);
if(i==null)
throw new SQLException("Fastpath:"+name+": no result returned, expected integer");
throw new PSQLException("postgresql.fp.expint",name);
return i.intValue();
}
@ -292,7 +292,7 @@ public class Fastpath
// so, until we know we can do this (needs testing, on the TODO list)
// for now, we throw the exception and do no lookups.
if(id==null)
throw new SQLException("Fastpath: function "+name+" is unknown");
throw new PSQLException("postgresql.fp.unknown",name);
return id.intValue();
}

View File

@ -67,7 +67,7 @@ public class PGbox extends PGobject implements Serializable,Cloneable
{
PGtokenizer t = new PGtokenizer(value,',');
if(t.getSize() != 2)
throw new SQLException("conversion of box failed - "+value);
throw new PSQLException("postgresql.geo.box",value);
point[0] = new PGpoint(t.getToken(0));
point[1] = new PGpoint(t.getToken(1));

View File

@ -67,13 +67,13 @@ public class PGcircle extends PGobject implements Serializable,Cloneable
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removeAngle(s),',');
if(t.getSize() != 2)
throw new SQLException("conversion of circle failed - "+s);
throw new PSQLException("postgresql.geo.circle",s);
try {
center = new PGpoint(t.getToken(0));
radius = Double.valueOf(t.getToken(1)).doubleValue();
} catch(NumberFormatException e) {
throw new SQLException("conversion of circle failed - "+s+" - +"+e.toString());
throw new PSQLException("postgresql.geo.circle",e);
}
}

View File

@ -65,7 +65,7 @@ public class PGline extends PGobject implements Serializable,Cloneable
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s),',');
if(t.getSize() != 2)
throw new SQLException("conversion of line failed - "+s);
throw new PSQLException("postgresql.geo.line",s);
point[0] = new PGpoint(t.getToken(0));
point[1] = new PGpoint(t.getToken(1));

View File

@ -62,7 +62,7 @@ public class PGlseg extends PGobject implements Serializable,Cloneable
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s),',');
if(t.getSize() != 2)
throw new SQLException("conversion of lseg failed - "+s);
throw new PSQLException("postgresql.geo.lseg");
point[0] = new PGpoint(t.getToken(0));
point[1] = new PGpoint(t.getToken(1));

View File

@ -62,7 +62,7 @@ public class PGpath extends PGobject implements Serializable,Cloneable
open = false;
s = PGtokenizer.removePara(s);
} else
throw new SQLException("cannot tell if path is open or closed");
throw new PSQLException("postgresql.geo.path");
PGtokenizer t = new PGtokenizer(s,',');
int npoints = t.getSize();

View File

@ -66,7 +66,7 @@ public class PGpoint extends PGobject implements Serializable,Cloneable
x = Double.valueOf(t.getToken(0)).doubleValue();
y = Double.valueOf(t.getToken(1)).doubleValue();
} catch(NumberFormatException e) {
throw new SQLException("conversion of point failed - "+e.toString());
throw new PSQLException("postgresql.geo.point",e.toString());
}
}

View File

@ -17,7 +17,7 @@ import postgresql.largeobject.*;
import postgresql.util.*;
/**
* $Id: Connection.java,v 1.1 1999/01/17 04:51:53 momjian Exp $
* $Id: Connection.java,v 1.2 1999/05/18 23:17:21 peter Exp $
*
* A Connection represents a session with a specific database. Within the
* context of a Connection, SQL statements are executed and results are
@ -96,7 +96,7 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
*/
public java.sql.CallableStatement prepareCall(String sql) throws SQLException
{
throw new SQLException("Callable Statements are not supported at this time");
throw new PSQLException("postgresql.con.call");
// return new CallableStatement(this, sql);
}
@ -311,7 +311,7 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
*/
public void setTransactionIsolation(int level) throws SQLException
{
throw new SQLException("Transaction Isolation Levels are not implemented");
throw postgresql.Driver.notImplemented();
}
/**

View File

@ -93,7 +93,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
@ -118,7 +118,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
@ -411,7 +411,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException
{
throw new SQLException("InputStream as parameter not supported");
throw postgresql.Driver.notImplemented();
}
/**
@ -486,7 +486,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
setString(parameterIndex, ((PGobject)x).getValue());
break;
default:
throw new SQLException("Unknown Types value");
throw new PSQLException("postgresql.prep.type");
}
}
@ -550,7 +550,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
@ -594,7 +594,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
private void set(int paramIndex, String s) throws SQLException
{
if (paramIndex < 1 || paramIndex > inStrings.length)
throw new SQLException("Parameter index out of range");
throw new PSQLException("postgresql.prep.range");
inStrings[paramIndex - 1] = s;
}
}

View File

@ -143,7 +143,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
//return null;
//return new String(bytes);
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column Index out of range");
throw new PSQLException("postgresql.res.colrange");
wasNullFlag = (this_row[columnIndex - 1] == null);
if(wasNullFlag)
return null;
@ -186,7 +186,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Byte.parseByte(s);
} catch (NumberFormatException e) {
throw new SQLException("Bad Byte Form: " + s);
throw new PSQLException("postgresql.res.badbyte",s);
}
}
return 0; // SQL NULL
@ -209,7 +209,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Short.parseShort(s);
} catch (NumberFormatException e) {
throw new SQLException("Bad Short Form: " + s);
throw new PSQLException("postgresql.res.badshort",s);
}
}
return 0; // SQL NULL
@ -232,7 +232,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Integer.parseInt(s);
} catch (NumberFormatException e) {
throw new SQLException ("Bad Integer Form: " + s);
throw new PSQLException ("postgresql.badint",s);
}
}
return 0; // SQL NULL
@ -255,7 +255,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Long.parseLong(s);
} catch (NumberFormatException e) {
throw new SQLException ("Bad Long Form: " + s);
throw new PSQLException ("postgresql.res.badlong",s);
}
}
return 0; // SQL NULL
@ -278,7 +278,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Float.valueOf(s).floatValue();
} catch (NumberFormatException e) {
throw new SQLException ("Bad Float Form: " + s);
throw new PSQLException ("postgresql.res.badfloat",s);
}
}
return 0; // SQL NULL
@ -301,7 +301,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Double.valueOf(s).doubleValue();
} catch (NumberFormatException e) {
throw new SQLException ("Bad Double Form: " + s);
throw new PSQLException ("postgresql.res.baddouble",s);
}
}
return 0; // SQL NULL
@ -327,13 +327,13 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
val = new BigDecimal(s);
} catch (NumberFormatException e) {
throw new SQLException ("Bad BigDecimal Form: " + s);
throw new PSQLException ("postgresql.res.badbigdec",s);
}
try
{
return val.setScale(scale);
} catch (ArithmeticException e) {
throw new SQLException ("Bad BigDecimal Form: " + s);
throw new PSQLException ("postgresql.res.badbigdec",s);
}
}
return null; // SQL NULL
@ -357,7 +357,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
public byte[] getBytes(int columnIndex) throws SQLException
{
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column Index out of range");
throw new PSQLException("postgresql.res.colrange");
wasNullFlag = (this_row[columnIndex - 1] == null);
// Handle OID's as BLOBS
@ -390,7 +390,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
try {
return new java.sql.Date(df.parse(s).getTime());
} catch (ParseException e) {
throw new SQLException("Bad Date Format: at " + e.getErrorOffset() + " in " + s);
throw new PSQLException("postgresql.res.baddate",new Integer(e.getErrorOffset()),s);
}
}
@ -417,7 +417,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
int sec = (s.length() == 5) ? 0 : Integer.parseInt(s.substring(6));
return new Time(hr, min, sec);
} catch (NumberFormatException e) {
throw new SQLException ("Bad Time Form: " + s);
throw new PSQLException ("postgresql.res.badtime",s);
}
}
return null; // SQL NULL
@ -448,7 +448,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
java.util.Date d = df.parse(s);
return new Timestamp(d.getTime());
} catch (ParseException e) {
throw new SQLException("Bad Timestamp Format: at " + e.getErrorOffset() + " in " + s);
throw new PSQLException("postgresql.res.badtimestamp",new Integer(e.getErrorOffset()),s);
}
}
return null; // SQL NULL
@ -697,7 +697,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
Field field;
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column index out of range");
throw new PSQLException("postgresql.res.colrange");
field = fields[columnIndex - 1];
// some fields can be null, mainly from those returned by MetaData methods
@ -770,7 +770,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
for (i = 0 ; i < fields.length; ++i)
if (fields[i].name.equalsIgnoreCase(columnName))
return (i+1);
throw new SQLException ("Column name not found");
throw new PSQLException ("postgresql.res.colname",columnName);
}
}

View File

@ -8,6 +8,7 @@ package postgresql.jdbc1;
import java.lang.*;
import java.util.*;
import postgresql.*;
import postgresql.util.*;
// We explicitly import classes here as the original line:
//import java.sql.*;
@ -424,7 +425,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
private Field getField(int columnIndex) throws SQLException
{
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column index out of range");
throw new PSQLException("postgresql.res.colrange");
return fields[columnIndex - 1];
}
}

View File

@ -7,6 +7,8 @@ package postgresql.jdbc1;
import java.sql.*;
import postgresql.util.PSQLException;
/**
* A Statement object is used for executing a static SQL statement and
* obtaining the results produced by it.
@ -52,7 +54,7 @@ public class Statement implements java.sql.Statement
while (result != null && !((postgresql.ResultSet)result).reallyResultSet())
result = ((postgresql.ResultSet)result).getNext();
if (result == null)
throw new SQLException("no results returned");
throw new PSQLException("postgresql.stat.noresult");
return result;
}
@ -69,7 +71,7 @@ public class Statement implements java.sql.Statement
{
this.execute(sql);
if (((postgresql.ResultSet)result).reallyResultSet())
throw new SQLException("results returned");
throw new PSQLException("postgresql.stat.result");
return this.getUpdateCount();
}
@ -114,7 +116,7 @@ public class Statement implements java.sql.Statement
*/
public void setMaxFieldSize(int max) throws SQLException
{
throw new SQLException("Attempt to setMaxFieldSize failed - compile time default");
throw new PSQLException("postgresql.stat.maxfieldsize");
}
/**

View File

@ -17,7 +17,7 @@ import postgresql.largeobject.*;
import postgresql.util.*;
/**
* $Id: Connection.java,v 1.1 1999/01/17 04:51:56 momjian Exp $
* $Id: Connection.java,v 1.2 1999/05/18 23:17:26 peter Exp $
*
* A Connection represents a session with a specific database. Within the
* context of a Connection, SQL statements are executed and results are
@ -96,7 +96,7 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
*/
public java.sql.CallableStatement prepareCall(String sql) throws SQLException
{
throw new SQLException("Callable Statements are not supported at this time");
throw new PSQLException("postgresql.con.call");
// return new CallableStatement(this, sql);
}
@ -311,7 +311,7 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
*/
public void setTransactionIsolation(int level) throws SQLException
{
throw new SQLException("Transaction Isolation Levels are not implemented");
throw postgresql.Driver.notImplemented();
}
/**

View File

@ -93,7 +93,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
@ -118,7 +118,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
@ -414,7 +414,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException
{
throw new SQLException("InputStream as parameter not supported");
throw new PSQLException("postgresql.prep.is");
}
/**
@ -489,7 +489,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
setString(parameterIndex, ((PGobject)x).getValue());
break;
default:
throw new SQLException("Unknown Types value");
throw new PSQLException("postgresql.prep.type");
}
}
@ -553,7 +553,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
@ -597,7 +597,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
private void set(int paramIndex, String s) throws SQLException
{
if (paramIndex < 1 || paramIndex > inStrings.length)
throw new SQLException("Parameter index out of range");
throw new PSQLException("postgresql.prep.range");
inStrings[paramIndex - 1] = s;
}

View File

@ -144,7 +144,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
//return null;
//return new String(bytes);
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column Index out of range");
throw new PSQLException("postgresql.res.colrange");
wasNullFlag = (this_row[columnIndex - 1] == null);
if(wasNullFlag)
return null;
@ -187,7 +187,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Byte.parseByte(s);
} catch (NumberFormatException e) {
throw new SQLException("Bad Byte Form: " + s);
throw new PSQLException("postgresql.res.badbyte",s);
}
}
return 0; // SQL NULL
@ -210,7 +210,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Short.parseShort(s);
} catch (NumberFormatException e) {
throw new SQLException("Bad Short Form: " + s);
throw new PSQLException("postgresql.res.badshort",s);
}
}
return 0; // SQL NULL
@ -233,7 +233,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Integer.parseInt(s);
} catch (NumberFormatException e) {
throw new SQLException ("Bad Integer Form: " + s);
throw new PSQLException ("postgresql.res.badint",s);
}
}
return 0; // SQL NULL
@ -256,7 +256,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Long.parseLong(s);
} catch (NumberFormatException e) {
throw new SQLException ("Bad Long Form: " + s);
throw new PSQLException ("postgresql.res.badlong",s);
}
}
return 0; // SQL NULL
@ -279,7 +279,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Float.valueOf(s).floatValue();
} catch (NumberFormatException e) {
throw new SQLException ("Bad Float Form: " + s);
throw new PSQLException ("postgresql.res.badfloat",s);
}
}
return 0; // SQL NULL
@ -302,7 +302,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
return Double.valueOf(s).doubleValue();
} catch (NumberFormatException e) {
throw new SQLException ("Bad Double Form: " + s);
throw new PSQLException ("postgresql.res.baddouble",s);
}
}
return 0; // SQL NULL
@ -329,13 +329,13 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
{
val = new BigDecimal(s);
} catch (NumberFormatException e) {
throw new SQLException ("Bad BigDecimal Form: " + s);
throw new PSQLException ("postgresql.res.badbigdec",s);
}
try
{
return val.setScale(scale);
} catch (ArithmeticException e) {
throw new SQLException ("Bad BigDecimal Form: " + s);
throw new PSQLException ("postgresql.res.badbigdec",s);
}
}
return null; // SQL NULL
@ -359,7 +359,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
public byte[] getBytes(int columnIndex) throws SQLException
{
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column Index out of range");
throw new PSQLException("postgresql.res.colrange");
wasNullFlag = (this_row[columnIndex - 1] == null);
// Handle OID's as BLOBS
@ -392,7 +392,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
try {
return new java.sql.Date(df.parse(s).getTime());
} catch (ParseException e) {
throw new SQLException("Bad Date Format: at " + e.getErrorOffset() + " in " + s);
throw new PSQLException("postgresql.res.baddate",new Integer(e.getErrorOffset()),s);
}
}
@ -419,7 +419,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
int sec = (s.length() == 5) ? 0 : Integer.parseInt(s.substring(6));
return new Time(hr, min, sec);
} catch (NumberFormatException e) {
throw new SQLException ("Bad Time Form: " + s);
throw new PSQLException ("postgresql.res.badtime",s);
}
}
return null; // SQL NULL
@ -450,7 +450,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
java.util.Date d = df.parse(s);
return new Timestamp(d.getTime());
} catch (ParseException e) {
throw new SQLException("Bad Timestamp Format: at " + e.getErrorOffset() + " in " + s);
throw new PSQLException("postgresql.res.badtimestamp",new Integer(e.getErrorOffset()),s);
}
}
return null; // SQL NULL
@ -711,7 +711,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
Field field;
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column index out of range");
throw new PSQLException("postgresql.res.colrange");
field = fields[columnIndex - 1];
// some fields can be null, mainly from those returned by MetaData methods
@ -784,7 +784,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
for (i = 0 ; i < fields.length; ++i)
if (fields[i].name.equalsIgnoreCase(columnName))
return (i+1);
throw new SQLException ("Column name not found");
throw new PSQLException ("postgresql.res.colname",columnName);
}
// ** JDBC 2 Extensions **

View File

@ -9,6 +9,7 @@ import java.lang.*;
import java.sql.*;
import java.util.*;
import postgresql.*;
import postgresql.util.*;
/**
* A ResultSetMetaData object can be used to find out about the types and
@ -419,7 +420,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
private Field getField(int columnIndex) throws SQLException
{
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column index out of range");
throw new PSQLException("postgresql.res.colrange");
return fields[columnIndex - 1];
}

View File

@ -7,6 +7,7 @@ package postgresql.jdbc2;
import java.sql.*;
import java.util.Vector;
import postgresql.util.*;
/**
* A Statement object is used for executing a static SQL statement and
@ -54,7 +55,7 @@ public class Statement implements java.sql.Statement
while (result != null && !((postgresql.ResultSet)result).reallyResultSet())
result = ((postgresql.ResultSet)result).getNext();
if (result == null)
throw new SQLException("no results returned");
throw new PSQLException("postgresql.stat.noresult");
return result;
}
@ -71,7 +72,7 @@ public class Statement implements java.sql.Statement
{
this.execute(sql);
if (((postgresql.ResultSet)result).reallyResultSet())
throw new SQLException("results returned");
throw new PSQLException("postgresql.stat.result");
return this.getUpdateCount();
}
@ -116,7 +117,7 @@ public class Statement implements java.sql.Statement
*/
public void setMaxFieldSize(int max) throws SQLException
{
throw new SQLException("Attempt to setMaxFieldSize failed - compile time default");
throw new PSQLException("postgresql.stat.maxfieldsize");
}
/**
@ -341,7 +342,7 @@ public class Statement implements java.sql.Statement
public int[] executeBatch() throws SQLException
{
if(batch==null || batch.isEmpty())
throw new SQLException("The batch is empty.");
throw new PSQLException("postgresql.stat.batch.empty");
int size=batch.size();
int[] result=new int[size];
@ -353,7 +354,7 @@ public class Statement implements java.sql.Statement
this.execute("commit"); // PTM: check this
} catch(SQLException e) {
this.execute("abort"); // PTM: check this
throw new SQLException("The result "+i+" \""+batch.elementAt(i)+"\" aborted.");
throw new PSQLException("postgresql.stat.batch.error",new Integer(i),batch.elementAt(i));
}
return result;
}

View File

@ -261,7 +261,7 @@ public class LargeObject
*/
public InputStream getInputStream() throws SQLException
{
throw new SQLException("LargeObject:getInputStream not implemented");
throw postgresql.Driver.notImplemented();
}
/**
@ -274,6 +274,6 @@ public class LargeObject
*/
public OutputStream getOutputStream() throws SQLException
{
throw new SQLException("LargeObject:getOutputStream not implemented");
throw postgresql.Driver.notImplemented();
}
}

View File

@ -7,6 +7,7 @@ import java.util.*;
import java.sql.*;
import postgresql.fastpath.*;
import postgresql.util.*;
/**
* This class implements the large object interface to postgresql.
@ -113,7 +114,7 @@ public class LargeObjectManager
" or proname = 'lowrite'");
if(res==null)
throw new SQLException("failed to initialise LargeObject API");
throw new PSQLException("postgresql.lo.init");
fp.addFunctions(res);
res.close();

View File

@ -65,7 +65,7 @@ public class PGmoney extends PGobject implements Serializable,Cloneable
val = negative ? -val : val;
} catch(NumberFormatException e) {
throw new SQLException("conversion of money failed - "+e.toString());
throw new PSQLException("postgresql.money",e);
}
}

View File

@ -45,6 +45,18 @@ public class PSQLException extends SQLException
translate(error,argv);
}
/**
* Helper version for 2 args
*/
public PSQLException(String error,Object arg1,Object arg2)
{
super();
Object[] argv = new Object[2];
argv[0] = arg1;
argv[1] = arg2;
translate(error,argv);
}
/**
* This does the actual translation
*/

View File

@ -45,7 +45,7 @@ public class Serialize
className = toClassName(type);
ourClass = Class.forName(className);
} catch(ClassNotFoundException cnfe) {
throw new SQLException("No class found for '"+type+"`");
throw new PSQLException("postgresql.serial.noclass",type);
}
// Second check, the type must be a table
@ -58,7 +58,7 @@ public class Serialize
}
// This should never occur, as postgresql has it's own internal checks
if(!status)
throw new SQLException("The table for "+type+" is not in the database. Contact the DBA, as the database is in an inconsistent state.");
throw new PSQLException("postgresql.serial.table",type);
// Finally cache the fields within the table
}
@ -106,7 +106,7 @@ public class Serialize
}
rs.close();
} else
throw new SQLException("Unexpected result from query");
throw new PSQLException("postgresql.unexpected");
return obj;
} catch(IllegalAccessException iae) {
throw new SQLException(iae.toString());
@ -231,7 +231,7 @@ public class Serialize
public static void create(postgresql.Connection con,Class c) throws SQLException
{
if(c.isInterface())
throw new SQLException("Cannot serialize an Interface");
throw new PSQLException("postgresql.serial.interface");
// See if the table exists
String tableName = toPostgreSQL(c.getName());
@ -316,10 +316,10 @@ public class Serialize
name = name.toLowerCase();
if(name.indexOf("_")>-1)
throw new SQLException("Class names may not have _ in them: "+name);
throw new PSQLException("postgresql.serial.underscore");
if(name.length()>32)
throw new SQLException("Class & Package name length cannot be longer than 32 characters. "+name+" is "+name.length()+" characters.");
throw new PSQLException("postgresql.serial.namelength",name,new Integer(name.length()));
return name.replace('.','_');
}