Commit 6a061da2 authored by Marc G. Fournier's avatar Marc G. Fournier

Update patch from Peter <patches@maidast.demon.co.uk>

parent 0b6dc93b
package postgresql;
import java.math.*;
import java.sql.*;
import java.math.*;
/**
* @version 1.0 15-APR-1997
* @author <A HREF="mailto:adrian@hottub.org">Adrian Hall</A>
*
* CallableStatement is used to execute SQL stored procedures.
*
* JDBC provides a stored procedure SQL escape that allows stored procedures
* to be called in a standard way for all RDBMS's. This escape syntax has
* one form that includes a result parameter and one that does not. If used,
* the result parameter must be generated as an OUT parameter. The other
* parameters may be used for input, output or both. Parameters are refered
* to sequentially, by number. The first parameter is 1.
*
* <PRE>
* {?= call <procedure-name>[<arg1>,<arg2>, ...]}
* {call <procedure-name>[<arg1>,<arg2>, ...]}
* </PRE>
*
* IN parameters are set using the set methods inherited from
* PreparedStatement. The type of all OUT parameters must be registered
* prior to executing the stored procedure; their values are retrieved
* after execution via the get methods provided here.
*
* A CallableStatement may return a ResultSet or multiple ResultSets. Multiple
* ResultSets are handled using operations inherited from Statement.
*
* For maximum portability, a call's ResultSets and update counts should be
* processed prior to getting the values of output parameters.
*
* @see java.sql.Connection#prepareCall
* @see java.sql.ResultSet
* @see java.sql.CallableStatement
* JDBC Interface to Postgres95 functions
*/
public class CallableStatement implements java.sql.CallableStatement
{
public void registerOutParameter (int paramterIndex, int sqlType) throws SQLException
{
// XXX-Not Implemented
}
public void registerOutParameter (int parameterIndex, int sqlType, int scale) throws SQLException
{
// XXX-Not Implemented
}
public boolean wasNull () throws SQLException
{
// XXX-Not Implemented
}
public String getString (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public boolean getBoolean (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public byte getByte (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public short getShort (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public int getInt (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public long getLong (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public float getFloat (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public double getDouble (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public BigDecimal getBigDecimal (int parameterIndex, int scale) throws SQLException
{
// XXX-Not Implemented
}
public byte[] getBytes (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public Date getDate (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public Time getTime (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public Timestamp getTimestamp (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
public Object getObject (int parameterIndex) throws SQLException
{
// XXX-Not Implemented
}
// Copy methods from the Result set object here.
public class CallableStatement extends PreparedStatement implements java.sql.CallableStatement
{
CallableStatement(Connection c,String q) throws SQLException
{
super(c,q);
}
// Before executing a stored procedure call you must explicitly
// call registerOutParameter to register the java.sql.Type of each
// out parameter.
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
}
// You must also specify the scale for numeric/decimal types:
public void registerOutParameter(int parameterIndex, int sqlType,
int scale) throws SQLException
{
}
public boolean isNull(int parameterIndex) throws SQLException {
return true;
}
// New API (JPM)
public boolean wasNull() throws SQLException {
// check to see if the last access threw an exception
return false; // fake it for now
}
// Methods for retrieving OUT parameters from this statement.
public String getChar(int parameterIndex) throws SQLException {
return null;
}
// New API (JPM)
public String getString(int parameterIndex) throws SQLException {
return null;
}
//public String getVarChar(int parameterIndex) throws SQLException {
// return null;
//}
public String getLongVarChar(int parameterIndex) throws SQLException {
return null;
}
// New API (JPM) (getBit)
public boolean getBoolean(int parameterIndex) throws SQLException {
return false;
}
// New API (JPM) (getTinyInt)
public byte getByte(int parameterIndex) throws SQLException {
return 0;
}
// New API (JPM) (getSmallInt)
public short getShort(int parameterIndex) throws SQLException {
return 0;
}
// New API (JPM) (getInteger)
public int getInt(int parameterIndex) throws SQLException {
return 0;
}
// New API (JPM) (getBigInt)
public long getLong(int parameterIndex) throws SQLException {
return 0;
}
public float getFloat(int parameterIndex) throws SQLException {
return (float) 0.0;
}
public double getDouble(int parameterIndex) throws SQLException {
return 0.0;
}
public BigDecimal getBigDecimal(int parameterIndex, int scale)
throws SQLException {
return null;
}
// New API (JPM) (getBinary)
public byte[] getBytes(int parameterIndex) throws SQLException {
return null;
}
// New API (JPM) (getLongVarBinary)
public byte[] getBinaryStream(int parameterIndex) throws SQLException {
return null;
}
public java.sql.Date getDate(int parameterIndex) throws SQLException {
return null;
}
public java.sql.Time getTime(int parameterIndex) throws SQLException {
return null;
}
public java.sql.Timestamp getTimestamp(int parameterIndex)
throws SQLException {
return null;
}
//----------------------------------------------------------------------
// Advanced features:
// You can obtain a ParameterMetaData object to get information
// about the parameters to this CallableStatement.
public DatabaseMetaData getMetaData() {
return null;
}
// getObject returns a Java object for the parameter.
// See the JDBC spec's "Dynamic Programming" chapter for details.
public Object getObject(int parameterIndex)
throws SQLException {
return null;
}
}
This diff is collapsed.
......@@ -13,77 +13,91 @@ import postgresql.*;
*/
public class Field
{
int length; // Internal Length of this field
int oid; // OID of the type
Connection conn; // Connection Instantation
String name; // Name of this field
int sql_type = -1; // The entry in java.sql.Types for this field
String type_name = null;// The sql type name
/**
* Construct a field based on the information fed to it.
*
* @param conn the connection this field came from
* @param name the name of the field
* @param oid the OID of the field
* @param len the length of the field
*/
public Field(Connection conn, String name, int oid, int length)
{
this.conn = conn;
this.name = name;
this.oid = oid;
this.length = length;
}
/**
* the ResultSet and ResultMetaData both need to handle the SQL
* type, which is gained from another query. Note that we cannot
* use getObject() in this, since getObject uses getSQLType().
*
* @return the entry in Types that refers to this field
* @exception SQLException if a database access error occurs
*/
public int getSQLType() throws SQLException
{
if (sql_type == -1)
{
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");
result.next();
type_name = result.getString(1);
if (type_name.equals("int2")) sql_type = Types.SMALLINT;
else if (type_name.equals("int4")) sql_type = Types.INTEGER;
else if (type_name.equals("int8")) sql_type = Types.BIGINT;
else if (type_name.equals("cash")) sql_type = Types.DECIMAL;
else if (type_name.equals("money")) sql_type = Types.DECIMAL;
else if (type_name.equals("float4")) sql_type = Types.REAL;
else if (type_name.equals("float8")) sql_type = Types.DOUBLE;
else if (type_name.equals("bpchar")) sql_type = Types.CHAR;
else if (type_name.equals("varchar")) sql_type = Types.VARCHAR;
else if (type_name.equals("bool")) sql_type = Types.BIT;
else if (type_name.equals("date")) sql_type = Types.DATE;
else if (type_name.equals("time")) sql_type = Types.TIME;
else if (type_name.equals("abstime")) sql_type = Types.TIMESTAMP;
else sql_type = Types.OTHER;
}
return sql_type;
}
/**
* We also need to get the type name as returned by the back end.
* This is held in type_name AFTER a call to getSQLType. Since
* we get this information within getSQLType (if it isn't already
* done), we can just call getSQLType and throw away the result.
*
* @return the String representation of the type of this field
* @exception SQLException if a database access error occurs
*/
public String getTypeName() throws SQLException
{
int sql = getSQLType();
return type_name;
}
int length; // Internal Length of this field
int oid; // OID of the type
Connection conn; // Connection Instantation
String name; // Name of this field
int sql_type = -1; // The entry in java.sql.Types for this field
String type_name = null;// The sql type name
/**
* Construct a field based on the information fed to it.
*
* @param conn the connection this field came from
* @param name the name of the field
* @param oid the OID of the field
* @param len the length of the field
*/
public Field(Connection conn, String name, int oid, int length)
{
this.conn = conn;
this.name = name;
this.oid = oid;
this.length = length;
}
/**
* the ResultSet and ResultMetaData both need to handle the SQL
* type, which is gained from another query. Note that we cannot
* use getObject() in this, since getObject uses getSQLType().
*
* @return the entry in Types that refers to this field
* @exception SQLException if a database access error occurs
*/
public int getSQLType() throws SQLException
{
if (sql_type == -1)
{
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");
result.next();
type_name = result.getString(1);
if (type_name.equals("int2"))
sql_type = Types.SMALLINT;
else if (type_name.equals("int4"))
sql_type = Types.INTEGER;
else if (type_name.equals("int8"))
sql_type = Types.BIGINT;
else if (type_name.equals("cash"))
sql_type = Types.DECIMAL;
else if (type_name.equals("money"))
sql_type = Types.DECIMAL;
else if (type_name.equals("float4"))
sql_type = Types.REAL;
else if (type_name.equals("float8"))
sql_type = Types.DOUBLE;
else if (type_name.equals("bpchar"))
sql_type = Types.CHAR;
else if (type_name.equals("varchar"))
sql_type = Types.VARCHAR;
else if (type_name.equals("bool"))
sql_type = Types.BIT;
else if (type_name.equals("date"))
sql_type = Types.DATE;
else if (type_name.equals("time"))
sql_type = Types.TIME;
else if (type_name.equals("abstime"))
sql_type = Types.TIMESTAMP;
else
sql_type = Types.OTHER;
}
return sql_type;
}
/**
* We also need to get the type name as returned by the back end.
* This is held in type_name AFTER a call to getSQLType. Since
* we get this information within getSQLType (if it isn't already
* done), we can just call getSQLType and throw away the result.
*
* @return the String representation of the type of this field
* @exception SQLException if a database access error occurs
*/
public String getTypeName() throws SQLException
{
int sql = getSQLType();
return type_name;
}
}
......@@ -14,18 +14,132 @@ import postgresql.*;
*/
public class PG_Object
{
public String type;
public String value;
/**
* Constructor for the PostgreSQL generic object
*
* @param type a string describing the type of the object
* @param value a string representation of the value of the object
*/
public PG_Object(String type, String value)
{
this.type = type;
this.value = value;
}
public String type;
public String value;
/**
* Constructor for the PostgreSQL generic object
*
* @param type a string describing the type of the object
* @param value a string representation of the value of the object
*/
public PG_Object(String type, String value) throws SQLException
{
this.type = type;
this.value = value;
}
/**
* This returns true if the object is a 'box'
*/
public boolean isBox()
{
return type.equals("box");
}
/**
* This returns a PGbox object, or null if it's not
* @return PGbox
*/
public PGbox getBox() throws SQLException
{
if(isBox())
return new PGbox(value);
return null;
}
/**
* This returns true if the object is a 'point'
*/
public boolean isCircle()
{
return type.equals("circle");
}
/**
* This returns a PGcircle object, or null if it's not
* @return PGcircle
*/
public PGcircle getCircle() throws SQLException
{
if(isCircle())
return new PGcircle(value);
return null;
}
/**
* This returns true if the object is a 'lseg' (line segment)
*/
public boolean isLseg()
{
return type.equals("lseg");
}
/**
* This returns a PGlsegobject, or null if it's not
* @return PGlseg
*/
public PGlseg getLseg() throws SQLException
{
if(isLseg())
return new PGlseg(value);
return null;
}
/**
* This returns true if the object is a 'path'
*/
public boolean isPath()
{
return type.equals("path");
}
/**
* This returns a PGpath object, or null if it's not
* @return PGpath
*/
public PGpath getPath() throws SQLException
{
if(isPath())
return new PGpath(value);
return null;
}
/**
* This returns true if the object is a 'point'
*/
public boolean isPoint()
{
return type.equals("point");
}
/**
* This returns a PGpoint object, or null if it's not
* @return PGpoint object
*/
public PGpoint getPoint() throws SQLException
{
if(isPoint())
return new PGpoint(value);
return null;
}
/**
* This returns true if the object is a 'polygon'
*/
public boolean isPolygon()
{
return type.equals("polygon");
}
/**
* This returns a PGpolygon object, or null if it's not
* @return PGpolygon
*/
public PGpolygon getPolygon() throws SQLException
{
if(isPolygon())
return new PGpolygon(value);
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment