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.
// 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);
// 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
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");
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
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');
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)
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)
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)
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)
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)
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)
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
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);
}
}
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;
/**
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);
public static SQLException notImplemented()
{
return new PSQLException("postgresql.unimplemented");
- //return new SQLException("This method is not yet implemented.");
}
}
import java.sql.*;
import java.util.*;
import postgresql.*;
+import postgresql.util.*;
/**
* postgresql.Field is a class used to describe fields in a PostgreSQL
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);
import java.util.*;
import java.sql.*;
import postgresql.*;
+import postgresql.util.*;
/**
* @version 1.0 15-APR-1997
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.
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;
}
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;
}
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;
}
{
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;
{
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);
}
}
try {
pg_output.flush();
} catch (IOException e) {
- throw new SQLException(FLUSH_MSG + e.toString());
+ throw new PSQLException("postgresql.stream.flush",e);
}
}
# 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.
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
//------------------------------
// Error message returned
case 'E':
- throw new SQLException("Fastpath: "+stream.ReceiveString(4096));
+ throw new PSQLException("postgresql.fp.error",stream.ReceiveString(4096));
//------------------------------
// Notice from backend
return result;
default:
- throw new SQLException("Fastpath: protocol error. Got '"+((char)in)+"'");
+ throw new PSQLException("postgresql.fp.protocol",new Character((char)in));
}
}
}
{
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();
}
// 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();
}
{
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));
{
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);
}
}
{
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));
{
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));
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();
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());
}
}
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
*/
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);
}
*/
public void setTransactionIsolation(int level) throws SQLException
{
- throw new SQLException("Transaction Isolation Levels are not implemented");
+ throw postgresql.Driver.notImplemented();
}
/**
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]);
}
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]);
}
*/
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException
{
- throw new SQLException("InputStream as parameter not supported");
+ throw postgresql.Driver.notImplemented();
}
/**
setString(parameterIndex, ((PGobject)x).getValue());
break;
default:
- throw new SQLException("Unknown Types value");
+ throw new PSQLException("postgresql.prep.type");
}
}
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]);
}
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;
}
}
//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;
{
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
{
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
{
return Integer.parseInt(s);
} catch (NumberFormatException e) {
- throw new SQLException ("Bad Integer Form: " + s);
+ throw new PSQLException ("postgresql.badint",s);
}
}
return 0; // SQL NULL
{
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
{
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
{
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
{
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
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
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);
}
}
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
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
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
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);
}
}
import java.lang.*;
import java.util.*;
import postgresql.*;
+import postgresql.util.*;
// We explicitly import classes here as the original line:
//import java.sql.*;
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];
}
}
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.
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;
}
{
this.execute(sql);
if (((postgresql.ResultSet)result).reallyResultSet())
- throw new SQLException("results returned");
+ throw new PSQLException("postgresql.stat.result");
return this.getUpdateCount();
}
*/
public void setMaxFieldSize(int max) throws SQLException
{
- throw new SQLException("Attempt to setMaxFieldSize failed - compile time default");
+ throw new PSQLException("postgresql.stat.maxfieldsize");
}
/**
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
*/
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);
}
*/
public void setTransactionIsolation(int level) throws SQLException
{
- throw new SQLException("Transaction Isolation Levels are not implemented");
+ throw postgresql.Driver.notImplemented();
}
/**
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]);
}
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]);
}
*/
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");
}
/**
setString(parameterIndex, ((PGobject)x).getValue());
break;
default:
- throw new SQLException("Unknown Types value");
+ throw new PSQLException("postgresql.prep.type");
}
}
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]);
}
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;
}
//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;
{
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
{
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
{
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
{
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
{
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
{
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
{
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
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
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);
}
}
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
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
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
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 **
import java.sql.*;
import java.util.*;
import postgresql.*;
+import postgresql.util.*;
/**
* A ResultSetMetaData object can be used to find out about the types and
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];
}
import java.sql.*;
import java.util.Vector;
+import postgresql.util.*;
/**
* A Statement object is used for executing a static SQL statement and
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;
}
{
this.execute(sql);
if (((postgresql.ResultSet)result).reallyResultSet())
- throw new SQLException("results returned");
+ throw new PSQLException("postgresql.stat.result");
return this.getUpdateCount();
}
*/
public void setMaxFieldSize(int max) throws SQLException
{
- throw new SQLException("Attempt to setMaxFieldSize failed - compile time default");
+ throw new PSQLException("postgresql.stat.maxfieldsize");
}
/**
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];
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;
}
*/
public InputStream getInputStream() throws SQLException
{
- throw new SQLException("LargeObject:getInputStream not implemented");
+ throw postgresql.Driver.notImplemented();
}
/**
*/
public OutputStream getOutputStream() throws SQLException
{
- throw new SQLException("LargeObject:getOutputStream not implemented");
+ throw postgresql.Driver.notImplemented();
}
}
import java.sql.*;
import postgresql.fastpath.*;
+import postgresql.util.*;
/**
* This class implements the large object interface to postgresql.
" 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();
val = negative ? -val : val;
} catch(NumberFormatException e) {
- throw new SQLException("conversion of money failed - "+e.toString());
+ throw new PSQLException("postgresql.money",e);
}
}
}
/**
+ * 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
*/
private void translate(String id,Object[] args)
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
}
// 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
}
}
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());
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());
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('.','_');
}