Minor bug fixes. Replaced DateStyle support with ISO.

This commit is contained in:
Peter Mount 1999-05-17 22:43:30 +00:00
parent c2b75c83f3
commit 3f59cc0831
16 changed files with 188 additions and 3923 deletions

View File

@ -1,3 +1,15 @@
Mon May 17 23:40:00 BST 1999
- PG_Stream.close() now attempts to send the close connection message
to the backend before closing the streams
- Added batch support in the JDBC2, supplied by Yutaka Tanida <yutaka@marin.or.jp>
- Removed the old datestyle code. Now the driver uses only ISO.
- Removed some files in the postgresql directory still in CVS that were
moved since 6.4.x (DatabaseMetaData.java PreparedStatement.java
ResultSetMetaData.java Statement.java)
- Internationalisation of the error messages is partially implemented, however
it's not enabled as it only works when the jar file is _not_ used, and
work needs to be done.
Sun Apr 11 17:00:00 BST 1999
- getUpdateCount() now returns the actual update count (before it
simply returned 1 for everything).

View File

@ -10,7 +10,7 @@ import postgresql.largeobject.*;
import postgresql.util.*;
/**
* $Id: Connection.java,v 1.15 1999/04/11 18:03:00 peter Exp $
* $Id: Connection.java,v 1.16 1999/05/17 22:43:23 peter Exp $
*
* This abstract class is used by postgresql.Driver to open either the JDBC1 or
* JDBC2 versions of the Connection class.
@ -67,38 +67,6 @@ public abstract class Connection
// be across all connections, which could be to different backends.
public Hashtable fieldCache = new Hashtable();
/**
* This is the current date style of the backend
*/
public int currentDateStyle;
/**
* This defines the formats for dates, according to the various date styles.
*
* <p>There are two strings for each entry. The first is the string to search
* for in the datestyle message, and the second the format to use.
*
* <p>To add a new date style, work out the format. Then with psql running
* in the date style you wish to add, type: show datestyle;
*
* <p>eg:
* <br><pre>
* => show datestyle;
* NOTICE: Datestyle is SQL with European conventions
* ^^^^^^^^^^^^^^^^^
* </pre>The marked part of the string is the first string below. The second
* is your format. If a style (like ISO) ignores the US/European variants,
* then you can ignore the "with" part of the string.
*/
protected static final String dateStyles[] = {
"Postgres with European", "dd-MM-yyyy",
"Postgres with US", "MM-dd-yyyy",
"ISO", "yyyy-MM-dd",
"SQL with European", "dd/MM/yyyy",
"SQL with US", "MM/dd/yyyy",
"German", "dd.MM.yyyy"
};
// Now handle notices as warnings, so things like "show" now work
public SQLWarning firstWarning = null;
@ -242,22 +210,24 @@ public abstract class Connection
throw new SQLException("Connection failed: " + e.toString());
}
// Find out the date style by issuing the SQL: show datestyle
// This actually issues a warning, and our own warning handling
// code handles this itself.
//
// Also, this query replaced the NULL query issued to test the
// connection.
//
// Originally we issued a SHOW DATESTYLE statement to find the databases default
// datestyle. However, this caused some problems with timestamps, so in 6.5, we
// went the way of ODBC, and set the connection to ISO.
//
// This may cause some clients to break when they assume anything other than ISO,
// but then - they should be using the proper methods ;-)
//
//
firstWarning = null;
ExecSQL("show datestyle");
// Initialise object handling
initObjectTypes();
// Mark the connection as ok, and cleanup
ExecSQL("set datestyle to 'ISO'");
// Initialise object handling
initObjectTypes();
// Mark the connection as ok, and cleanup
firstWarning = null;
PG_STATUS = CONNECTION_OK;
PG_STATUS = CONNECTION_OK;
}
// These methods used to be in the main Connection implementation. As they
@ -280,23 +250,18 @@ public abstract class Connection
// Now check for some specific messages
// This is obsolete in 6.5, but I've left it in here so if we need to use this
// technique again, we'll know where to place it.
//
// This is generated by the SQL "show datestyle"
if(msg.startsWith("NOTICE:") && msg.indexOf("DateStyle")>0) {
// 13 is the length off "DateStyle is "
msg = msg.substring(msg.indexOf("DateStyle is ")+13);
for(int i=0;i<dateStyles.length;i+=2)
if(msg.startsWith(dateStyles[i]))
currentDateStyle=i+1; // this is the index of the format
}
}
/**
* @return the date format for the current date style of the backend
*/
public String getDateStyle()
{
return dateStyles[currentDateStyle];
//if(msg.startsWith("NOTICE:") && msg.indexOf("DateStyle")>0) {
//// 13 is the length off "DateStyle is "
//msg = msg.substring(msg.indexOf("DateStyle is ")+13);
//
//for(int i=0;i<dateStyles.length;i+=2)
//if(msg.startsWith(dateStyles[i]))
//currentDateStyle=i+1; // this is the index of the format
//}
}
/**

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,13 @@ 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;
/**
* The Java SQL framework allows for multiple database drivers. Each
* driver should supply a class that implements the Driver interface
@ -101,8 +108,10 @@ public class Driver implements java.sql.Driver
con.openConnection (host(), port(), props, database(), url, this);
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
@ -346,6 +355,7 @@ 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

@ -378,6 +378,8 @@ public class PG_Stream
*/
public void close() throws IOException
{
pg_output.write("X\0".getBytes());
pg_output.flush();
pg_output.close();
pg_input.close();
connection.close();

View File

@ -1,595 +0,0 @@
package postgresql;
import java.io.*;
import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import postgresql.largeobject.*;
import postgresql.util.*;
/**
* A SQL Statement is pre-compiled and stored in a PreparedStatement object.
* This object can then be used to efficiently execute this statement multiple
* times.
*
* <p><B>Note:</B> The setXXX methods for setting IN parameter values must
* specify types that are compatible with the defined SQL type of the input
* parameter. For instance, if the IN parameter has SQL type Integer, then
* setInt should be used.
*
* <p>If arbitrary parameter type conversions are required, then the setObject
* method should be used with a target SQL type.
*
* @see ResultSet
* @see java.sql.PreparedStatement
*/
public class PreparedStatement extends Statement implements java.sql.PreparedStatement
{
String sql;
String[] templateStrings;
String[] inStrings;
Connection connection;
/**
* Constructor for the PreparedStatement class.
* Split the SQL statement into segments - separated by the arguments.
* When we rebuild the thing with the arguments, we can substitute the
* args and join the whole thing together.
*
* @param conn the instanatiating connection
* @param sql the SQL statement with ? for IN markers
* @exception SQLException if something bad occurs
*/
public PreparedStatement(Connection connection, String sql) throws SQLException
{
super(connection);
Vector v = new Vector();
boolean inQuotes = false;
int lastParmEnd = 0, i;
this.sql = sql;
this.connection = connection;
for (i = 0; i < sql.length(); ++i)
{
int c = sql.charAt(i);
if (c == '\'')
inQuotes = !inQuotes;
if (c == '?' && !inQuotes)
{
v.addElement(sql.substring (lastParmEnd, i));
lastParmEnd = i + 1;
}
}
v.addElement(sql.substring (lastParmEnd, sql.length()));
templateStrings = new String[v.size()];
inStrings = new String[v.size() - 1];
clearParameters();
for (i = 0 ; i < templateStrings.length; ++i)
templateStrings[i] = (String)v.elementAt(i);
}
/**
* A Prepared SQL query is executed and its ResultSet is returned
*
* @return a ResultSet that contains the data produced by the
* query - never null
* @exception SQLException if a database access error occurs
*/
public java.sql.ResultSet executeQuery() throws SQLException
{
StringBuffer s = new StringBuffer();
int i;
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
s.append(templateStrings[inStrings.length]);
return super.executeQuery(s.toString()); // in Statement class
}
/**
* Execute a SQL INSERT, UPDATE or DELETE statement. In addition,
* SQL statements that return nothing such as SQL DDL statements can
* be executed.
*
* @return either the row count for INSERT, UPDATE or DELETE; or
* 0 for SQL statements that return nothing.
* @exception SQLException if a database access error occurs
*/
public int executeUpdate() throws SQLException
{
StringBuffer s = new StringBuffer();
int i;
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
s.append(templateStrings[inStrings.length]);
return super.executeUpdate(s.toString()); // in Statement class
}
/**
* Set a parameter to SQL NULL
*
* <p><B>Note:</B> You must specify the parameters SQL type (although
* PostgreSQL ignores it)
*
* @param parameterIndex the first parameter is 1, etc...
* @param sqlType the SQL type code defined in java.sql.Types
* @exception SQLException if a database access error occurs
*/
public void setNull(int parameterIndex, int sqlType) throws SQLException
{
set(parameterIndex, "null");
}
/**
* Set a parameter to a Java boolean value. The driver converts this
* to a SQL BIT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setBoolean(int parameterIndex, boolean x) throws SQLException
{
set(parameterIndex, x ? "'t'" : "'f'");
}
/**
* Set a parameter to a Java byte value. The driver converts this to
* a SQL TINYINT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setByte(int parameterIndex, byte x) throws SQLException
{
set(parameterIndex, (new Integer(x)).toString());
}
/**
* Set a parameter to a Java short value. The driver converts this
* to a SQL SMALLINT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setShort(int parameterIndex, short x) throws SQLException
{
set(parameterIndex, (new Integer(x)).toString());
}
/**
* Set a parameter to a Java int value. The driver converts this to
* a SQL INTEGER value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setInt(int parameterIndex, int x) throws SQLException
{
set(parameterIndex, (new Integer(x)).toString());
}
/**
* Set a parameter to a Java long value. The driver converts this to
* a SQL BIGINT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setLong(int parameterIndex, long x) throws SQLException
{
set(parameterIndex, (new Long(x)).toString());
}
/**
* Set a parameter to a Java float value. The driver converts this
* to a SQL FLOAT value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setFloat(int parameterIndex, float x) throws SQLException
{
set(parameterIndex, (new Float(x)).toString());
}
/**
* Set a parameter to a Java double value. The driver converts this
* to a SQL DOUBLE value when it sends it to the database
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setDouble(int parameterIndex, double x) throws SQLException
{
set(parameterIndex, (new Double(x)).toString());
}
/**
* Set a parameter to a java.lang.BigDecimal value. The driver
* converts this to a SQL NUMERIC value when it sends it to the
* database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
{
set(parameterIndex, x.toString());
}
/**
* Set a parameter to a Java String value. The driver converts this
* to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments
* size relative to the driver's limits on VARCHARs) when it sends it
* to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setString(int parameterIndex, String x) throws SQLException
{
// if the passed string is null, then set this column to null
if(x==null)
set(parameterIndex,"null");
else {
StringBuffer b = new StringBuffer();
int i;
b.append('\'');
for (i = 0 ; i < x.length() ; ++i)
{
char c = x.charAt(i);
if (c == '\\' || c == '\'')
b.append((char)'\\');
b.append(c);
}
b.append('\'');
set(parameterIndex, b.toString());
}
}
/**
* Set a parameter to a Java array of bytes. The driver converts this
* to a SQL VARBINARY or LONGVARBINARY (depending on the argument's
* size relative to the driver's limits on VARBINARYs) when it sends
* it to the database.
*
* <p>Implementation note:
* <br>With postgresql, this creates a large object, and stores the
* objects oid in this column.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setBytes(int parameterIndex, byte x[]) throws SQLException
{
LargeObjectManager lom = connection.getLargeObjectAPI();
int oid = lom.create();
LargeObject lob = lom.open(oid);
lob.write(x);
lob.close();
setInt(parameterIndex,oid);
}
/**
* Set a parameter to a java.sql.Date value. The driver converts this
* to a SQL DATE value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
{
SimpleDateFormat df = new SimpleDateFormat("''"+connection.getDateStyle()+"''");
set(parameterIndex, df.format(x));
// The above is how the date should be handled.
//
// However, in JDK's prior to 1.1.6 (confirmed with the
// Linux jdk1.1.3 and the Win95 JRE1.1.5), SimpleDateFormat seems
// to format a date to the previous day. So the fix is to add a day
// before formatting.
//
// PS: 86400000 is one day
//
//set(parameterIndex, df.format(new java.util.Date(x.getTime()+86400000)));
}
/**
* Set a parameter to a java.sql.Time value. The driver converts
* this to a SQL TIME value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...));
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setTime(int parameterIndex, Time x) throws SQLException
{
set(parameterIndex, "'" + x.toString() + "'");
}
/**
* Set a parameter to a java.sql.Timestamp value. The driver converts
* this to a SQL TIMESTAMP value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
{
set(parameterIndex, "'" + x.toString() + "'");
}
/**
* When a very large ASCII value is input to a LONGVARCHAR parameter,
* it may be more practical to send it via a java.io.InputStream.
* JDBC will read the data from the stream as needed, until it reaches
* end-of-file. The JDBC driver will do any necessary conversion from
* ASCII to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard Java
* stream object or your own subclass that implements the standard
* interface.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @param length the number of bytes in the stream
* @exception SQLException if a database access error occurs
*/
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException
{
setBinaryStream(parameterIndex, x, length);
}
/**
* When a very large Unicode value is input to a LONGVARCHAR parameter,
* it may be more practical to send it via a java.io.InputStream.
* JDBC will read the data from the stream as needed, until it reaches
* end-of-file. The JDBC driver will do any necessary conversion from
* UNICODE to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard Java
* stream object or your own subclass that implements the standard
* interface.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException
{
setBinaryStream(parameterIndex, x, length);
}
/**
* When a very large binary value is input to a LONGVARBINARY parameter,
* it may be more practical to send it via a java.io.InputStream.
* JDBC will read the data from the stream as needed, until it reaches
* end-of-file.
*
* <P><B>Note:</B> This stream object can either be a standard Java
* stream object or your own subclass that implements the standard
* interface.
*
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
* @exception SQLException if a database access error occurs
*/
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException
{
throw new SQLException("InputStream as parameter not supported");
}
/**
* In general, parameter values remain in force for repeated used of a
* Statement. Setting a parameter value automatically clears its
* previous value. However, in coms cases, it is useful to immediately
* release the resources used by the current parameter values; this
* can be done by calling clearParameters
*
* @exception SQLException if a database access error occurs
*/
public void clearParameters() throws SQLException
{
int i;
for (i = 0 ; i < inStrings.length ; i++)
inStrings[i] = null;
}
/**
* Set the value of a parameter using an object; use the java.lang
* equivalent objects for integral values.
*
* <P>The given Java object will be converted to the targetSqlType before
* being sent to the database.
*
* <P>note that this method may be used to pass database-specific
* abstract data types. This is done by using a Driver-specific
* Java type and using a targetSqlType of java.sql.Types.OTHER
*
* @param parameterIndex the first parameter is 1...
* @param x the object containing the input parameter value
* @param targetSqlType The SQL type to be send to the database
* @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC
* types this is the number of digits after the decimal. For
* all other types this value will be ignored.
* @exception SQLException if a database access error occurs
*/
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException
{
switch (targetSqlType)
{
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.REAL:
case Types.FLOAT:
case Types.DOUBLE:
case Types.DECIMAL:
case Types.NUMERIC:
if (x instanceof Boolean)
set(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0");
else
set(parameterIndex, x.toString());
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
setString(parameterIndex, x.toString());
break;
case Types.DATE:
setDate(parameterIndex, (java.sql.Date)x);
break;
case Types.TIME:
setTime(parameterIndex, (Time)x);
break;
case Types.TIMESTAMP:
setTimestamp(parameterIndex, (Timestamp)x);
break;
case Types.OTHER:
setString(parameterIndex, ((PGobject)x).getValue());
break;
default:
throw new SQLException("Unknown Types value");
}
}
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException
{
setObject(parameterIndex, x, targetSqlType, 0);
}
/**
* This stores an Object into a parameter.
* <p>New for 6.4, if the object is not recognised, but it is
* Serializable, then the object is serialised using the
* postgresql.util.Serialize class.
*/
public void setObject(int parameterIndex, Object x) throws SQLException
{
if (x instanceof String)
setString(parameterIndex, (String)x);
else if (x instanceof BigDecimal)
setBigDecimal(parameterIndex, (BigDecimal)x);
else if (x instanceof Short)
setShort(parameterIndex, ((Short)x).shortValue());
else if (x instanceof Integer)
setInt(parameterIndex, ((Integer)x).intValue());
else if (x instanceof Long)
setLong(parameterIndex, ((Long)x).longValue());
else if (x instanceof Float)
setFloat(parameterIndex, ((Float)x).floatValue());
else if (x instanceof Double)
setDouble(parameterIndex, ((Double)x).doubleValue());
else if (x instanceof byte[])
setBytes(parameterIndex, (byte[])x);
else if (x instanceof java.sql.Date)
setDate(parameterIndex, (java.sql.Date)x);
else if (x instanceof Time)
setTime(parameterIndex, (Time)x);
else if (x instanceof Timestamp)
setTimestamp(parameterIndex, (Timestamp)x);
else if (x instanceof Boolean)
setBoolean(parameterIndex, ((Boolean)x).booleanValue());
else if (x instanceof PGobject)
setString(parameterIndex, ((PGobject)x).getValue());
else
setLong(parameterIndex, connection.putObject(x));
}
/**
* Some prepared statements return multiple results; the execute method
* handles these complex statements as well as the simpler form of
* statements handled by executeQuery and executeUpdate
*
* @return true if the next result is a ResultSet; false if it is an
* update count or there are no more results
* @exception SQLException if a database access error occurs
*/
public boolean execute() throws SQLException
{
StringBuffer s = new StringBuffer();
int i;
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
throw new SQLException("No value specified for parameter " + (i + 1));
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
s.append(templateStrings[inStrings.length]);
return super.execute(s.toString()); // in Statement class
}
/**
* Returns the SQL statement with the current template values
* substituted.
*/
public String toString() {
StringBuffer s = new StringBuffer();
int i;
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
s.append( '?' );
else
s.append (templateStrings[i]);
s.append (inStrings[i]);
}
s.append(templateStrings[inStrings.length]);
return s.toString();
}
// **************************************************************
// END OF PUBLIC INTERFACE
// **************************************************************
/**
* There are a lot of setXXX classes which all basically do
* the same thing. We need a method which actually does the
* set for us.
*
* @param paramIndex the index into the inString
* @param s a string to be stored
* @exception SQLException if something goes wrong
*/
private void set(int paramIndex, String s) throws SQLException
{
if (paramIndex < 1 || paramIndex > inStrings.length)
throw new SQLException("Parameter index out of range");
inStrings[paramIndex - 1] = s;
}
}

View File

@ -1,421 +0,0 @@
package postgresql;
import java.lang.*;
import java.sql.*;
import java.util.*;
import postgresql.*;
/**
* A ResultSetMetaData object can be used to find out about the types and
* properties of the columns in a ResultSet
*
* @see java.sql.ResultSetMetaData
*/
public class ResultSetMetaData implements java.sql.ResultSetMetaData
{
Vector rows;
Field[] fields;
/**
* Initialise for a result with a tuple set and
* a field descriptor set
*
* @param rows the Vector of rows returned by the ResultSet
* @param fields the array of field descriptors
*/
public ResultSetMetaData(Vector rows, Field[] fields)
{
this.rows = rows;
this.fields = fields;
}
/**
* Whats the number of columns in the ResultSet?
*
* @return the number
* @exception SQLException if a database access error occurs
*/
public int getColumnCount() throws SQLException
{
return fields.length;
}
/**
* Is the column automatically numbered (and thus read-only)
* I believe that PostgreSQL does not support this feature.
*
* @param column the first column is 1, the second is 2...
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean isAutoIncrement(int column) throws SQLException
{
return false;
}
/**
* Does a column's case matter? ASSUMPTION: Any field that is
* not obviously case insensitive is assumed to be case sensitive
*
* @param column the first column is 1, the second is 2...
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean isCaseSensitive(int column) throws SQLException
{
int sql_type = getField(column).getSQLType();
switch (sql_type)
{
case Types.SMALLINT:
case Types.INTEGER:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
return false;
default:
return true;
}
}
/**
* Can the column be used in a WHERE clause? Basically for
* this, I split the functions into two types: recognised
* types (which are always useable), and OTHER types (which
* may or may not be useable). The OTHER types, for now, I
* will assume they are useable. We should really query the
* catalog to see if they are useable.
*
* @param column the first column is 1, the second is 2...
* @return true if they can be used in a WHERE clause
* @exception SQLException if a database access error occurs
*/
public boolean isSearchable(int column) throws SQLException
{
int sql_type = getField(column).getSQLType();
// This switch is pointless, I know - but it is a set-up
// for further expansion.
switch (sql_type)
{
case Types.OTHER:
return true;
default:
return true;
}
}
/**
* Is the column a cash value? 6.1 introduced the cash/money
* type, which haven't been incorporated as of 970414, so I
* just check the type name for both 'cash' and 'money'
*
* @param column the first column is 1, the second is 2...
* @return true if its a cash column
* @exception SQLException if a database access error occurs
*/
public boolean isCurrency(int column) throws SQLException
{
String type_name = getField(column).getTypeName();
return type_name.equals("cash") || type_name.equals("money");
}
/**
* Can you put a NULL in this column? I think this is always
* true in 6.1's case. It would only be false if the field had
* been defined NOT NULL (system catalogs could be queried?)
*
* @param column the first column is 1, the second is 2...
* @return one of the columnNullable values
* @exception SQLException if a database access error occurs
*/
public int isNullable(int column) throws SQLException
{
return columnNullable; // We can always put NULL in
}
/**
* Is the column a signed number? In PostgreSQL, all numbers
* are signed, so this is trivial. However, strings are not
* signed (duh!)
*
* @param column the first column is 1, the second is 2...
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean isSigned(int column) throws SQLException
{
int sql_type = getField(column).getSQLType();
switch (sql_type)
{
case Types.SMALLINT:
case Types.INTEGER:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
return true;
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
return false; // I don't know about these?
default:
return false;
}
}
/**
* What is the column's normal maximum width in characters?
*
* @param column the first column is 1, the second is 2, etc.
* @return the maximum width
* @exception SQLException if a database access error occurs
*/
public int getColumnDisplaySize(int column) throws SQLException
{
int max = getColumnLabel(column).length();
int i;
for (i = 0 ; i < rows.size(); ++i)
{
byte[][] x = (byte[][])(rows.elementAt(i));
if(x[column-1]!=null) {
int xl = x[column - 1].length;
if (xl > max)
max = xl;
}
}
return max;
}
/**
* What is the suggested column title for use in printouts and
* displays? We suggest the ColumnName!
*
* @param column the first column is 1, the second is 2, etc.
* @return the column label
* @exception SQLException if a database access error occurs
*/
public String getColumnLabel(int column) throws SQLException
{
return getColumnName(column);
}
/**
* What's a column's name?
*
* @param column the first column is 1, the second is 2, etc.
* @return the column name
* @exception SQLException if a database access error occurs
*/
public String getColumnName(int column) throws SQLException
{
Field f = getField(column);
if(f!=null)
return f.name;
return "field"+column;
}
/**
* What is a column's table's schema? This relies on us knowing
* the table name....which I don't know how to do as yet. The
* JDBC specification allows us to return "" if this is not
* applicable.
*
* @param column the first column is 1, the second is 2...
* @return the Schema
* @exception SQLException if a database access error occurs
*/
public String getSchemaName(int column) throws SQLException
{
return "";
}
/**
* What is a column's number of decimal digits.
*
* @param column the first column is 1, the second is 2...
* @return the precision
* @exception SQLException if a database access error occurs
*/
public int getPrecision(int column) throws SQLException
{
int sql_type = getField(column).getSQLType();
switch (sql_type)
{
case Types.SMALLINT:
return 5;
case Types.INTEGER:
return 10;
case Types.REAL:
return 8;
case Types.FLOAT:
return 16;
case Types.DOUBLE:
return 16;
case Types.VARCHAR:
return 0;
default:
return 0;
}
}
/**
* What is a column's number of digits to the right of the
* decimal point?
*
* @param column the first column is 1, the second is 2...
* @return the scale
* @exception SQLException if a database access error occurs
*/
public int getScale(int column) throws SQLException
{
int sql_type = getField(column).getSQLType();
switch (sql_type)
{
case Types.SMALLINT:
return 0;
case Types.INTEGER:
return 0;
case Types.REAL:
return 8;
case Types.FLOAT:
return 16;
case Types.DOUBLE:
return 16;
case Types.VARCHAR:
return 0;
default:
return 0;
}
}
/**
* Whats a column's table's name? How do I find this out? Both
* getSchemaName() and getCatalogName() rely on knowing the table
* Name, so we need this before we can work on them.
*
* @param column the first column is 1, the second is 2...
* @return column name, or "" if not applicable
* @exception SQLException if a database access error occurs
*/
public String getTableName(int column) throws SQLException
{
return "";
}
/**
* What's a column's table's catalog name? As with getSchemaName(),
* we can say that if getTableName() returns n/a, then we can too -
* otherwise, we need to work on it.
*
* @param column the first column is 1, the second is 2...
* @return catalog name, or "" if not applicable
* @exception SQLException if a database access error occurs
*/
public String getCatalogName(int column) throws SQLException
{
return "";
}
/**
* What is a column's SQL Type? (java.sql.Type int)
*
* @param column the first column is 1, the second is 2, etc.
* @return the java.sql.Type value
* @exception SQLException if a database access error occurs
* @see postgresql.Field#getSQLType
* @see java.sql.Types
*/
public int getColumnType(int column) throws SQLException
{
return getField(column).getSQLType();
}
/**
* Whats is the column's data source specific type name?
*
* @param column the first column is 1, the second is 2, etc.
* @return the type name
* @exception SQLException if a database access error occurs
*/
public String getColumnTypeName(int column) throws SQLException
{
return getField(column).getTypeName();
}
/**
* Is the column definitely not writable? In reality, we would
* have to check the GRANT/REVOKE stuff for this to be effective,
* and I haven't really looked into that yet, so this will get
* re-visited.
*
* @param column the first column is 1, the second is 2, etc.
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean isReadOnly(int column) throws SQLException
{
return false;
}
/**
* Is it possible for a write on the column to succeed? Again, we
* would in reality have to check the GRANT/REVOKE stuff, which
* I haven't worked with as yet. However, if it isn't ReadOnly, then
* it is obviously writable.
*
* @param column the first column is 1, the second is 2, etc.
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean isWritable(int column) throws SQLException
{
if (isReadOnly(column))
return false;
else
return true;
}
/**
* Will a write on this column definately succeed? Hmmm...this
* is a bad one, since the two preceding functions have not been
* really defined. I cannot tell is the short answer. I thus
* return isWritable() just to give us an idea.
*
* @param column the first column is 1, the second is 2, etc..
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean isDefinitelyWritable(int column) throws SQLException
{
return isWritable(column);
}
// ********************************************************
// END OF PUBLIC INTERFACE
// ********************************************************
/**
* For several routines in this package, we need to convert
* a columnIndex into a Field[] descriptor. Rather than do
* the same code several times, here it is.
*
* @param columnIndex the first column is 1, the second is 2...
* @return the Field description
* @exception SQLException if a database access error occurs
*/
private Field getField(int columnIndex) throws SQLException
{
if (columnIndex < 1 || columnIndex > fields.length)
throw new SQLException("Column index out of range");
return fields[columnIndex - 1];
}
}

View File

@ -1,315 +0,0 @@
package postgresql;
import java.sql.*;
/**
* A Statement object is used for executing a static SQL statement and
* obtaining the results produced by it.
*
* <p>Only one ResultSet per Statement can be open at any point in time.
* Therefore, if the reading of one ResultSet is interleaved with the
* reading of another, each must have been generated by different
* Statements. All statement execute methods implicitly close a
* statement's current ResultSet if an open one exists.
*
* @see java.sql.Statement
* @see ResultSet
*/
public class Statement implements java.sql.Statement
{
Connection connection; // The connection who created us
ResultSet result = null; // The current results
SQLWarning warnings = null; // The warnings chain.
int timeout = 0; // The timeout for a query (not used)
boolean escapeProcessing = true;// escape processing flag
/**
* Constructor for a Statement. It simply sets the connection
* that created us.
*
* @param c the Connection instantation that creates us
*/
public Statement (Connection c)
{
connection = c;
}
/**
* Execute a SQL statement that returns a single ResultSet
*
* @param sql typically a static SQL SELECT statement
* @return a ResulSet that contains the data produced by the query
* @exception SQLException if a database access error occurs
*/
public java.sql.ResultSet executeQuery(String sql) throws SQLException
{
this.execute(sql);
while (result != null && !result.reallyResultSet())
result = result.getNext();
if (result == null)
throw new SQLException("no results returned");
return result;
}
/**
* Execute a SQL INSERT, UPDATE or DELETE statement. In addition
* SQL statements that return nothing such as SQL DDL statements
* can be executed
*
* @param sql a SQL statement
* @return either a row count, or 0 for SQL commands
* @exception SQLException if a database access error occurs
*/
public int executeUpdate(String sql) throws SQLException
{
this.execute(sql);
if (result.reallyResultSet())
throw new SQLException("results returned");
return this.getUpdateCount();
}
/**
* In many cases, it is desirable to immediately release a
* Statement's database and JDBC resources instead of waiting
* for this to happen when it is automatically closed. The
* close method provides this immediate release.
*
* <p><B>Note:</B> A Statement is automatically closed when it is
* garbage collected. When a Statement is closed, its current
* ResultSet, if one exists, is also closed.
*
* @exception SQLException if a database access error occurs (why?)
*/
public void close() throws SQLException
{
result = null;
}
/**
* The maxFieldSize limit (in bytes) is the maximum amount of
* data returned for any column value; it only applies to
* BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR and LONGVARCHAR
* columns. If the limit is exceeded, the excess data is silently
* discarded.
*
* @return the current max column size limit; zero means unlimited
* @exception SQLException if a database access error occurs
*/
public int getMaxFieldSize() throws SQLException
{
return 8192; // We cannot change this
}
/**
* Sets the maxFieldSize - NOT! - We throw an SQLException just
* to inform them to stop doing this.
*
* @param max the new max column size limit; zero means unlimited
* @exception SQLException if a database access error occurs
*/
public void setMaxFieldSize(int max) throws SQLException
{
throw new SQLException("Attempt to setMaxFieldSize failed - compile time default");
}
/**
* The maxRows limit is set to limit the number of rows that
* any ResultSet can contain. If the limit is exceeded, the
* excess rows are silently dropped.
*
* @return the current maximum row limit; zero means unlimited
* @exception SQLException if a database access error occurs
*/
public int getMaxRows() throws SQLException
{
return connection.maxrows;
}
/**
* Set the maximum number of rows
*
* @param max the new max rows limit; zero means unlimited
* @exception SQLException if a database access error occurs
* @see getMaxRows
*/
public void setMaxRows(int max) throws SQLException
{
connection.maxrows = max;
}
/**
* If escape scanning is on (the default), the driver will do escape
* substitution before sending the SQL to the database.
*
* @param enable true to enable; false to disable
* @exception SQLException if a database access error occurs
*/
public void setEscapeProcessing(boolean enable) throws SQLException
{
escapeProcessing = enable;
}
/**
* The queryTimeout limit is the number of seconds the driver
* will wait for a Statement to execute. If the limit is
* exceeded, a SQLException is thrown.
*
* @return the current query timeout limit in seconds; 0 = unlimited
* @exception SQLException if a database access error occurs
*/
public int getQueryTimeout() throws SQLException
{
return timeout;
}
/**
* Sets the queryTimeout limit
*
* @param seconds - the new query timeout limit in seconds
* @exception SQLException if a database access error occurs
*/
public void setQueryTimeout(int seconds) throws SQLException
{
timeout = seconds;
}
/**
* Cancel can be used by one thread to cancel a statement that
* is being executed by another thread. However, PostgreSQL is
* a sync. sort of thing, so this really has no meaning - we
* define it as a no-op (i.e. you can't cancel, but there is no
* error if you try.)
*
* @exception SQLException only because thats the spec.
*/
public void cancel() throws SQLException
{
// No-op
}
/**
* The first warning reported by calls on this Statement is
* returned. A Statement's execute methods clear its SQLWarning
* chain. Subsequent Statement warnings will be chained to this
* SQLWarning.
*
* <p>The Warning chain is automatically cleared each time a statement
* is (re)executed.
*
* <p><B>Note:</B> If you are processing a ResultSet then any warnings
* associated with ResultSet reads will be chained on the ResultSet
* object.
*
* @return the first SQLWarning on null
* @exception SQLException if a database access error occurs
*/
public SQLWarning getWarnings() throws SQLException
{
return warnings;
}
/**
* After this call, getWarnings returns null until a new warning
* is reported for this Statement.
*
* @exception SQLException if a database access error occurs (why?)
*/
public void clearWarnings() throws SQLException
{
warnings = null;
}
/**
* setCursorName defines the SQL cursor name that will be used by
* subsequent execute methods. This name can then be used in SQL
* positioned update/delete statements to identify the current row
* in the ResultSet generated by this statement. If a database
* doesn't support positioned update/delete, this method is a
* no-op.
*
* <p><B>Note:</B> By definition, positioned update/delete execution
* must be done by a different Statement than the one which
* generated the ResultSet being used for positioning. Also, cursor
* names must be unique within a Connection.
*
* <p>We throw an additional constriction. There can only be one
* cursor active at any one time.
*
* @param name the new cursor name
* @exception SQLException if a database access error occurs
*/
public void setCursorName(String name) throws SQLException
{
connection.setCursorName(name);
}
/**
* Execute a SQL statement that may return multiple results. We
* don't have to worry about this since we do not support multiple
* ResultSets. You can use getResultSet or getUpdateCount to
* retrieve the result.
*
* @param sql any SQL statement
* @return true if the next result is a ResulSet, false if it is
* an update count or there are no more results
* @exception SQLException if a database access error occurs
*/
public boolean execute(String sql) throws SQLException
{
result = connection.ExecSQL(sql);
return (result != null && result.reallyResultSet());
}
/**
* getResultSet returns the current result as a ResultSet. It
* should only be called once per result.
*
* @return the current result set; null if there are no more
* @exception SQLException if a database access error occurs (why?)
*/
public java.sql.ResultSet getResultSet() throws SQLException
{
return result;
}
/**
* getUpdateCount returns the current result as an update count,
* if the result is a ResultSet or there are no more results, -1
* is returned. It should only be called once per result.
*
* @return the current result as an update count.
* @exception SQLException if a database access error occurs
*/
public int getUpdateCount() throws SQLException
{
if (result == null) return -1;
if (result.reallyResultSet()) return -1;
return result.getResultCount();
}
/**
* getMoreResults moves to a Statement's next result. If it returns
* true, this result is a ResulSet.
*
* @return true if the next ResultSet is valid
* @exception SQLException if a database access error occurs
*/
public boolean getMoreResults() throws SQLException
{
result = result.getNext();
return (result != null && result.reallyResultSet());
}
/**
* Returns the status message from the current Result.<p>
* This is used internally by the driver.
*
* @return status message from backend
*/
public String getResultStatusString()
{
if(result == null)
return null;
return result.getStatusString();
}
}

View File

@ -0,0 +1,4 @@
# This is the default errors
postgresql.jvm.version:The postgresql.jar file does not contain the correct JDBC classes for this JVM. Try rebuilding.\nException thrown was {1}
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.

View File

@ -0,0 +1,4 @@
# This is the default errors
postgresql.jvm.version:Le fichier de postgresql.jar ne contient pas les classes correctes de JDBC pour ce JVM. Try que rebuilding.\nException jet<65>ées <20>était {1}
postgresql.unusual:Quelque chose de peu commun s'est produit pour faire <20>échouer le gestionnaire. Veuillez enregistrer cette exception: {1}
postgresql.unimplemented:Cette m<>éthode n'est pas encore appliqu<71>ée.

View File

@ -312,7 +312,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
{
SimpleDateFormat df = new SimpleDateFormat("''"+connection.getDateStyle()+"''");
SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''");
set(parameterIndex, df.format(x));

View File

@ -386,7 +386,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
String s = getString(columnIndex);
if(s==null)
return null;
SimpleDateFormat df = new SimpleDateFormat(connection.getDateStyle());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
return new java.sql.Date(df.parse(s).getTime());
} catch (ParseException e) {
@ -443,7 +443,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
TimeZone zone = TimeZone.getDefault();
zone.setRawOffset(TZ);
String nm = zone.getID();
s = s.substring(0,18) + nm;
s = s.substring(0,19) + nm;
try {
java.util.Date d = df.parse(s);
return new Timestamp(d.getTime());

View File

@ -312,7 +312,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
*/
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
{
SimpleDateFormat df = new SimpleDateFormat("''"+connection.getDateStyle()+"''");
SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''");
set(parameterIndex, df.format(x));

View File

@ -388,7 +388,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
String s = getString(columnIndex);
if(s==null)
return null;
SimpleDateFormat df = new SimpleDateFormat(connection.getDateStyle());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
return new java.sql.Date(df.parse(s).getTime());
} catch (ParseException e) {
@ -445,7 +445,7 @@ public class ResultSet extends postgresql.ResultSet implements java.sql.ResultSe
TimeZone zone = TimeZone.getDefault();
zone.setRawOffset(TZ);
String nm = zone.getID();
s = s.substring(0,18) + nm;
s = s.substring(0,19) + nm;
try {
java.util.Date d = df.parse(s);
return new Timestamp(d.getTime());

View File

@ -6,6 +6,7 @@ package postgresql.jdbc2;
// postgresql.jdbc1 package.
import java.sql.*;
import java.util.Vector;
/**
* A Statement object is used for executing a static SQL statement and
@ -27,6 +28,7 @@ public class Statement implements java.sql.Statement
SQLWarning warnings = null; // The warnings chain.
int timeout = 0; // The timeout for a query (not used)
boolean escapeProcessing = true;// escape processing flag
private Vector batch=null;
/**
* Constructor for a Statement. It simply sets the connection
@ -325,17 +327,35 @@ public class Statement implements java.sql.Statement
public void addBatch(String sql) throws SQLException
{
throw postgresql.Driver.notImplemented();
if(batch==null)
batch=new Vector();
batch.addElement(sql);
}
public void clearBatch() throws SQLException
{
throw postgresql.Driver.notImplemented();
if(batch!=null)
batch.removeAllElements();
}
public int[] executeBatch() throws SQLException
{
throw postgresql.Driver.notImplemented();
if(batch==null || batch.isEmpty())
throw new SQLException("The batch is empty.");
int size=batch.size();
int[] result=new int[size];
int i=0;
this.execute("begin"); // PTM: check this when autoCommit is false
try {
for(i=0;i<size;i++)
result[i]=this.executeUpdate((String)batch.elementAt(i));
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.");
}
return result;
}
public java.sql.Connection getConnection() throws SQLException

View File

@ -0,0 +1,99 @@
package postgresql.util;
import java.sql.*;
import java.text.*;
import java.util.*;
/**
* This class extends SQLException, and provides our internationalisation handling
*/
public class PSQLException extends SQLException
{
private String message;
// Cache for future errors
static ResourceBundle bundle;
/**
* This provides the same functionality to SQLException
* @param error Error string
*/
public PSQLException(String error) {
super();
translate(error,null);
}
/**
* A more generic entry point.
* @param error Error string or standard message id
* @param args Array of arguments
*/
public PSQLException(String error,Object[] args)
{
super();
translate(error,args);
}
/**
* Helper version for 1 arg
*/
public PSQLException(String error,Object arg)
{
super();
Object[] argv = new Object[1];
argv[0] = arg;
translate(error,argv);
}
/**
* This does the actual translation
*/
private void translate(String id,Object[] args)
{
if(bundle == null) {
try {
bundle = ResourceBundle.getBundle("postgresql.errors");
} catch(MissingResourceException e) {
}
}
// Now look up a localized message. If one is not found, then use
// the supplied message instead.
message = null;
try {
message = bundle.getString(id);
} catch(MissingResourceException e) {
message = id;
}
// Expand any arguments
if(args!=null)
message = MessageFormat.format(message,args);
}
/**
* Overides Throwable
*/
public String getLocalizedMessage()
{
return message;
}
/**
* Overides Throwable
*/
public String getMessage()
{
return message;
}
/**
* Overides Object
*/
public String toString()
{
return message;
}
}