1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

Attached is a patch to fix the current issues with building under jdbc1.

This patch moves the logic that looks up TypeOid, PGTypeName, and
SQLTypeName from Field to Connection.  It is moved to connection since
it needs to differ from the jdbc1 to jdbc2 versions and Connection
already has different subclasses for the two driver versions.  It also
made sense to move the logic to Connection as some of the logic was
already there anyway.

Barry Lind
This commit is contained in:
Bruce Momjian
2001-08-24 16:50:18 +00:00
parent 968d7733a1
commit 76a6da8a1b
12 changed files with 311 additions and 188 deletions

View File

@ -169,11 +169,11 @@ public class Array implements java.sql.Array
}
public int getBaseType() throws SQLException {
return Field.getSQLType( getBaseTypeName() );
return conn.getSQLType(getBaseTypeName());
}
public String getBaseTypeName() throws SQLException {
String fType = field.getTypeName();
String fType = field.getPGType();
if( fType.charAt(0) == '_' )
fType = fType.substring(1);
return fType;
@ -195,12 +195,12 @@ public class Array implements java.sql.Array
Object array = getArray( index, count, map );
Vector rows = new Vector();
Field[] fields = new Field[2];
fields[0] = new Field(conn, "INDEX", field.getOID("int2"), 2);
fields[0] = new Field(conn, "INDEX", conn.getOID("int2"), 2);
switch ( getBaseType() )
{
case Types.BIT:
boolean[] booleanArray = (boolean[]) array;
fields[1] = new Field(conn, "VALUE", field.getOID("bool"), 1);
fields[1] = new Field(conn, "VALUE", conn.getOID("bool"), 1);
for( int i=0; i<booleanArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -208,11 +208,11 @@ public class Array implements java.sql.Array
rows.addElement(tuple);
}
case Types.SMALLINT:
fields[1] = new Field(conn, "VALUE", field.getOID("int2"), 2);
fields[1] = new Field(conn, "VALUE", conn.getOID("int2"), 2);
case Types.INTEGER:
int[] intArray = (int[]) array;
if( fields[1] == null )
fields[1] = new Field(conn, "VALUE", field.getOID("int4"), 4);
fields[1] = new Field(conn, "VALUE", conn.getOID("int4"), 4);
for( int i=0; i<intArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -222,7 +222,7 @@ public class Array implements java.sql.Array
break;
case Types.BIGINT:
long[] longArray = (long[]) array;
fields[1] = new Field(conn, "VALUE", field.getOID("int8"), 8);
fields[1] = new Field(conn, "VALUE", conn.getOID("int8"), 8);
for( int i=0; i<longArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -232,7 +232,7 @@ public class Array implements java.sql.Array
break;
case Types.NUMERIC:
BigDecimal[] bdArray = (BigDecimal[]) array;
fields[1] = new Field(conn, "VALUE", field.getOID("numeric"), -1);
fields[1] = new Field(conn, "VALUE", conn.getOID("numeric"), -1);
for( int i=0; i<bdArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -242,7 +242,7 @@ public class Array implements java.sql.Array
break;
case Types.REAL:
float[] floatArray = (float[]) array;
fields[1] = new Field(conn, "VALUE", field.getOID("float4"), 4);
fields[1] = new Field(conn, "VALUE", conn.getOID("float4"), 4);
for( int i=0; i<floatArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -252,7 +252,7 @@ public class Array implements java.sql.Array
break;
case Types.DOUBLE:
double[] doubleArray = (double[]) array;
fields[1] = new Field(conn, "VALUE", field.getOID("float8"), 8);
fields[1] = new Field(conn, "VALUE", conn.getOID("float8"), 8);
for( int i=0; i<doubleArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -261,11 +261,11 @@ public class Array implements java.sql.Array
}
break;
case Types.CHAR:
fields[1] = new Field(conn, "VALUE", field.getOID("char"), 1);
fields[1] = new Field(conn, "VALUE", conn.getOID("char"), 1);
case Types.VARCHAR:
String[] strArray = (String[]) array;
if( fields[1] == null )
fields[1] = new Field(conn, "VALUE", field.getOID("varchar"), -1);
fields[1] = new Field(conn, "VALUE", conn.getOID("varchar"), -1);
for( int i=0; i<strArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -275,7 +275,7 @@ public class Array implements java.sql.Array
break;
case Types.DATE:
java.sql.Date[] dateArray = (java.sql.Date[]) array;
fields[1] = new Field(conn, "VALUE", field.getOID("date"), 4);
fields[1] = new Field(conn, "VALUE", conn.getOID("date"), 4);
for( int i=0; i<dateArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -285,7 +285,7 @@ public class Array implements java.sql.Array
break;
case Types.TIME:
java.sql.Time[] timeArray = (java.sql.Time[]) array;
fields[1] = new Field(conn, "VALUE", field.getOID("time"), 8);
fields[1] = new Field(conn, "VALUE", conn.getOID("time"), 8);
for( int i=0; i<timeArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
@ -295,7 +295,7 @@ public class Array implements java.sql.Array
break;
case Types.TIMESTAMP:
java.sql.Timestamp[] timestampArray = (java.sql.Timestamp[]) array;
fields[1] = new Field(conn, "VALUE", field.getOID("timestamp"), 8);
fields[1] = new Field(conn, "VALUE", conn.getOID("timestamp"), 8);
for( int i=0; i<timestampArray.length; i++ ) {
byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index

View File

@ -17,7 +17,7 @@ import org.postgresql.largeobject.*;
import org.postgresql.util.*;
/**
* $Id: Connection.java,v 1.9 2001/07/30 14:51:19 momjian Exp $
* $Id: Connection.java,v 1.10 2001/08/24 16:50:16 momjian Exp $
*
* A Connection represents a session with a specific database. Within the
* context of a Connection, SQL statements are executed and results are
@ -254,6 +254,77 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
// Default to the original method
return super.getObject(type,value);
}
/* An implementation of the abstract method in the parent class.
* This implemetation uses the jdbc2Types array to support the jdbc2
* datatypes. Basically jdbc1 and jdbc2 are the same, except that
* jdbc2 adds the Array types.
*/
public int getSQLType(String pgTypeName)
{
int sqlType = Types.OTHER; // default value
for(int i=0;i<jdbc2Types.length;i++) {
if(pgTypeName.equals(jdbc2Types[i])) {
sqlType=jdbc2Typei[i];
break;
}
}
return sqlType;
}
/**
* This table holds the org.postgresql names for the types supported.
* Any types that map to Types.OTHER (eg POINT) don't go into this table.
* They default automatically to Types.OTHER
*
* Note: This must be in the same order as below.
*
* Tip: keep these grouped together by the Types. value
*/
private static final String jdbc2Types[] = {
"int2",
"int4","oid",
"int8",
"cash","money",
"numeric",
"float4",
"float8",
"bpchar","char","char2","char4","char8","char16",
"varchar","text","name","filename",
"bool",
"date",
"time",
"abstime","timestamp",
"_bool", "_char", "_int2", "_int4", "_text", "_oid", "_varchar", "_int8",
"_float4", "_float8", "_abstime", "_date", "_time", "_timestamp", "_numeric"
};
/**
* This table holds the JDBC type for each entry above.
*
* Note: This must be in the same order as above
*
* Tip: keep these grouped together by the Types. value
*/
private static final int jdbc2Typei[] = {
Types.SMALLINT,
Types.INTEGER,Types.INTEGER,
Types.BIGINT,
Types.DOUBLE,Types.DOUBLE,
Types.NUMERIC,
Types.REAL,
Types.DOUBLE,
Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,
Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
Types.BIT,
Types.DATE,
Types.TIME,
Types.TIMESTAMP,Types.TIMESTAMP,
Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY,
Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY, Types.ARRAY
};
}
// ***********************************************************************

View File

@ -1963,7 +1963,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
dr.next();
String typname=dr.getString(1);
dr.close();
tuple[4] = Integer.toString(Field.getSQLType(typname)).getBytes(); // Data type
tuple[4] = Integer.toString(connection.getSQLType(typname)).getBytes(); // Data type
tuple[5] = typname.getBytes(); // Type name
// Column size
@ -2600,7 +2600,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
byte[][] tuple = new byte[18][];
String typname=rs.getString(1);
tuple[0] = typname.getBytes();
tuple[1] = Integer.toString(Field.getSQLType(typname)).getBytes();
tuple[1] = Integer.toString(connection.getSQLType(typname)).getBytes();
tuple[2] = b9; // for now
tuple[6] = bnn; // for now
tuple[7] = bf; // false for now - not case sensitive

View File

@ -657,7 +657,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
return new Long(getLong(columnIndex));
case Types.NUMERIC:
return getBigDecimal
(columnIndex, (field.mod==-1)?-1:((field.mod-4) & 0xffff));
(columnIndex, (field.getMod()==-1)?-1:((field.getMod()-4) & 0xffff));
case Types.REAL:
return new Float(getFloat(columnIndex));
case Types.DOUBLE:
@ -675,7 +675,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
case Types.VARBINARY:
return getBytes(columnIndex);
default:
return connection.getObject(field.getTypeName(), getString(columnIndex));
return connection.getObject(field.getPGType(), getString(columnIndex));
}
}
@ -711,7 +711,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
int i;
for (i = 0 ; i < fields.length; ++i)
if (fields[i].name.equalsIgnoreCase(columnName))
if (fields[i].getName().equalsIgnoreCase(columnName))
return (i+1);
throw new PSQLException ("postgresql.res.colname",columnName);
}

View File

@ -125,7 +125,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
*/
public boolean isCurrency(int column) throws SQLException
{
String type_name = getField(column).getTypeName();
String type_name = getField(column).getPGType();
return type_name.equals("cash") || type_name.equals("money");
}
@ -184,9 +184,9 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
public int getColumnDisplaySize(int column) throws SQLException
{
Field f = getField(column);
String type_name = f.getTypeName();
String type_name = f.getPGType();
int sql_type = f.getSQLType();
int typmod = f.mod;
int typmod = f.getMod();
// I looked at other JDBC implementations and couldn't find a consistent
// interpretation of the "display size" for numeric values, so this is our's
@ -214,7 +214,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
+ 1 + ( typmod & 0xffff ); // DECIMAL(p,s) = (p digits).(s digits)
// if we don't know better
return f.length;
return f.getLength();
}
/**
@ -241,7 +241,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
{
Field f = getField(column);
if(f!=null)
return f.name;
return f.getName();
return "field"+column;
}
@ -288,7 +288,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
case Types.NUMERIC:
Field f = getField(column);
if(f != null)
return ((0xFFFF0000)&f.mod)>>16;
return ((0xFFFF0000)&f.getMod())>>16;
else
return 0;
default:
@ -325,7 +325,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
case Types.NUMERIC:
Field f = getField(column);
if(f != null)
return (((0x0000FFFF)&f.mod)-4);
return (((0x0000FFFF)&f.getMod())-4);
else
return 0;
default:
@ -384,7 +384,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
*/
public String getColumnTypeName(int column) throws SQLException
{
return getField(column).getTypeName();
return getField(column).getPGType();
}
/**