diff --git a/src/interfaces/jdbc/org/postgresql/Connection.java b/src/interfaces/jdbc/org/postgresql/Connection.java
index b08de0d53ef4a15f2fbccff50b81e4d4c7a2f3e4..8218f517ef3e7098c2de1bc84194c92f0f7afc00 100644
--- a/src/interfaces/jdbc/org/postgresql/Connection.java
+++ b/src/interfaces/jdbc/org/postgresql/Connection.java
@@ -11,7 +11,7 @@ import org.postgresql.util.*;
 import org.postgresql.core.Encoding;
 
 /**
- * $Id: Connection.java,v 1.25 2001/08/10 14:42:07 momjian Exp $
+ * $Id: Connection.java,v 1.26 2001/08/24 16:50:12 momjian Exp $
  *
  * This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
  * JDBC2 versions of the Connection class.
@@ -69,11 +69,10 @@ public abstract class Connection
   // New for 6.3, salt value for crypt authorisation
   private String salt;
 
-  // This is used by Field to cache oid -> names.
-  // It's here, because it's shared across this connection only.
-  // Hence it cannot be static within the Field class, because it would then
-  // be across all connections, which could be to different backends.
-  public Hashtable fieldCache = new Hashtable();
+  // These are used to cache oids, PGTypes and SQLTypes
+  private static Hashtable sqlTypeCache = new Hashtable();  // oid -> SQLType
+  private static Hashtable pgTypeCache = new Hashtable();  // oid -> PGType
+  private static Hashtable typeOidCache = new Hashtable();  //PGType -> oid
 
   // Now handle notices as warnings, so things like "show" now work
   public SQLWarning firstWarning = null;
@@ -1108,5 +1107,86 @@ public abstract class Connection
   {
       return (getDBVersionNumber().compareTo(ver) >= 0);
   }
+
+
+  /**
+   * This returns the java.sql.Types type for a PG type oid
+   *
+   * @param oid PostgreSQL type oid
+   * @return the java.sql.Types type
+   * @exception SQLException if a database access error occurs
+   */
+  public int getSQLType(int oid) throws SQLException
+  {
+    Integer sqlType = (Integer)typeOidCache.get(new Integer(oid));
+
+    // it's not in the cache, so perform a query, and add the result to the cache
+    if(sqlType==null) {
+      ResultSet result = (org.postgresql.ResultSet)ExecSQL("select typname from pg_type where oid = " + oid);
+      if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
+        throw new PSQLException("postgresql.unexpected");
+      result.next();
+      String pgType = result.getString(1);
+      Integer iOid = new Integer(oid);
+      sqlType = new Integer(getSQLType(result.getString(1)));
+      sqlTypeCache.put(iOid,sqlType);
+      pgTypeCache.put(iOid,pgType);
+      result.close();
+    }
+
+    return sqlType.intValue();
+  }
+
+  /**
+   * This returns the java.sql.Types type for a PG type
+   *
+   * @param pgTypeName PostgreSQL type name
+   * @return the java.sql.Types type
+   */
+  public abstract int getSQLType(String pgTypeName);
+
+  /**
+   * This returns the oid for a given PG data type
+   * @param typeName PostgreSQL type name
+   * @return PostgreSQL oid value for a field of this type
+   */
+  public int getOID(String typeName) throws SQLException
+  {
+        int oid = -1;
+        if(typeName != null) {
+          Integer oidValue = (Integer) typeOidCache.get(typeName);
+          if(oidValue != null) {
+            oid = oidValue.intValue();
+          } else {
+            // it's not in the cache, so perform a query, and add the result to the cache
+            ResultSet result = (org.postgresql.ResultSet)ExecSQL("select oid from pg_type where typname='"
+                                + typeName + "'");
+            if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
+              throw new PSQLException("postgresql.unexpected");
+            result.next();
+            oid = Integer.parseInt(result.getString(1));
+            typeOidCache.put(typeName, new Integer(oid));
+            result.close();
+          }
+        }
+        return oid;
+  }
+
+  /**
+   * We also need to get the PG type name as returned by the back end.
+   *
+   * @return the String representation of the type of this field
+   * @exception SQLException if a database access error occurs
+   */
+  public String getPGType(int oid) throws SQLException
+  {
+    String pgType = (String) pgTypeCache.get(new Integer(oid));
+    if(pgType == null) {
+      getSQLType(oid);
+      pgType = (String) pgTypeCache.get(new Integer(oid));
+    }
+    return pgType;
+  }
+
 }
    
diff --git a/src/interfaces/jdbc/org/postgresql/Field.java b/src/interfaces/jdbc/org/postgresql/Field.java
index 8b4dcb868e4b0d137b85a0216416d43a6a19d51b..1bbc272aa80febaad218dac16f35c5f8dcf72245 100644
--- a/src/interfaces/jdbc/org/postgresql/Field.java
+++ b/src/interfaces/jdbc/org/postgresql/Field.java
@@ -12,17 +12,13 @@ import org.postgresql.util.*;
  */
 public class Field
 {
-  public int length;		// Internal Length of this field
-  public int oid;		// OID of the type
-  public int mod;		// type modifier of this field
-  public String name;		// Name of this field
+  private int length;		// Internal Length of this field
+  private int oid;		// OID of the type
+  private int mod;		// type modifier of this field
+  private String name;		// Name of this field
 
-  protected Connection conn;	// Connection Instantation
+  private Connection conn;	// Connection Instantation
 
-  public int sql_type = -1;	// The entry in java.sql.Types for this field
-  public String type_name = null;// The sql type name
-
-  private static Hashtable oidCache = new Hashtable();
 
   /**
    * Construct a field based on the information fed to it.
@@ -63,140 +59,49 @@ public class Field
   }
 
   /**
-   * 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
+   * @return the mod of this Field's data type
    */
-  public int getSQLType() throws SQLException
+  public int getMod()
   {
-    if(sql_type == -1) {
-      type_name = (String)conn.fieldCache.get(new Integer(oid));
-
-      // it's not in the cache, so perform a query, and add the result to
-      // the cache
-      if(type_name==null) {
-	ResultSet result = (org.postgresql.ResultSet)conn.ExecSQL("select typname from pg_type where oid = " + oid);
-	if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
-	  throw new PSQLException("postgresql.unexpected");
-	result.next();
-	type_name = result.getString(1);
-	conn.fieldCache.put(new Integer(oid),type_name);
-	result.close();
-      }
-
-      sql_type = getSQLType(type_name);
-    }
-    return sql_type;
+    return mod;
   }
 
   /**
-   * This returns the SQL type. It is called by the Field and DatabaseMetaData classes
-   * @param type_name PostgreSQL type name
-   * @return java.sql.Types value for oid
+   * @return the name of this Field's data type
    */
-  public static int getSQLType(String type_name)
+  public String getName()
   {
-    int sql_type = Types.OTHER; // default value
-    for(int i=0;i<types.length;i++)
-      if(type_name.equals(types[i]))
-	sql_type=typei[i];
-    return sql_type;
+    return name;
   }
 
   /**
-   * This returns the oid for a field of a given data type
-   * @param type_name PostgreSQL type name
-   * @return PostgreSQL oid value for a field of this type
+   * @return the length of this Field's data type
    */
-  public int getOID( String type_name ) throws SQLException
+  public int getLength()
   {
-	int oid = -1;
-	if(type_name != null) {
-		Integer oidValue = (Integer) oidCache.get( type_name );
-		if( oidValue != null ) 
-			oid = oidValue.intValue();
-		else {
-			// it's not in the cache, so perform a query, and add the result to the cache
-			ResultSet result = (org.postgresql.ResultSet)conn.ExecSQL("select oid from pg_type where typname='" 
-				+ type_name + "'");
-			if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
-				throw new PSQLException("postgresql.unexpected");
-			result.next();
-			oid = Integer.parseInt(result.getString(1));
-			oidCache.put( type_name, new Integer(oid) );
-			result.close();
-		}
-	}
-	return oid;
+    return length;
   }
 
   /**
-   * 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 types[] = {
-    "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.
+   * We also need to get the PG type name as returned by the back end.
    *
-   * Note: This must be in the same order as above
-   *
-   * Tip: keep these grouped together by the Types. value
+   * @return the String representation of the PG type of this field
+   * @exception SQLException if a database access error occurs
    */
-  private static final int typei[] = {
-    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
-  };
+  public String getPGType() throws SQLException
+  {
+    return conn.getPGType(oid);
+  }
 
   /**
-   * 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.
+   * We also need to get the java.sql.types type.
    *
-   * @return the String representation of the type of this field
+   * @return the int representation of the java.sql.types type of this field
    * @exception SQLException if a database access error occurs
    */
-  public String getTypeName() throws SQLException
+  public int getSQLType() throws SQLException
   {
-    int sql = getSQLType();
-    return type_name;
+    return conn.getSQLType(oid);
   }
+
 }
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java
index 0dab654030f3d81fb83c0a71c14bcb94635522ff..a809d33f5cd681836e44582f2e232e4650b1f8ff 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java
@@ -17,7 +17,7 @@ import org.postgresql.largeobject.*;
 import org.postgresql.util.*;
 
 /**
- * $Id: Connection.java,v 1.7 2001/07/30 14:51:19 momjian Exp $
+ * $Id: Connection.java,v 1.8 2001/08/24 16:50:15 momjian Exp $
  *
  * A Connection represents a session with a specific database.  Within the
  * context of a Connection, SQL statements are executed and results are
@@ -137,6 +137,73 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
 	return new org.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn,fields,tuples,status,updateCount,insertOID);
     }
 
+
+  /* An implementation of the abstract method in the parent class.
+   * This implemetation uses the jdbc1Types array to support the jdbc1
+   * 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<jdbc1Types.length;i++) {
+      if(pgTypeName.equals(jdbc1Types[i])) {
+        sqlType=jdbc1Typei[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 jdbc1Types[] = {
+    "int2",
+    "int4","oid",
+    "int8",
+    "cash","money",
+    "numeric",
+    "float4",
+    "float8",
+    "bpchar","char","char2","char4","char8","char16",
+    "varchar","text","name","filename",
+    "bool",
+    "date",
+    "time",
+    "abstime","timestamp"
+  };
+
+  /**
+   * 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 jdbc1Typei[] = {
+    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
+  };
+
+
 }
 
 // ***********************************************************************
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java
index 6ac4ffa04e8ed9c02b95f18ed93e7255434884d5..a87c34e771f1f94fb014ae5b921fc5b78aaff92a 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java
@@ -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
@@ -2596,7 +2596,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
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
index 0a28f7eb3ed108ac6285b1d708bea3a53995ff67..f1c5fe1fcb4b903edab0096274b98fa95097b35f 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
@@ -782,7 +782,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
       case Types.BIGINT:
 	return new Long(getLong(columnIndex));
       case Types.NUMERIC:
-	return getBigDecimal(columnIndex, ((field.mod-4) & 0xffff));
+        return getBigDecimal(columnIndex, ((field.getMod()-4) & 0xffff));
       case Types.REAL:
 	return new Float(getFloat(columnIndex));
       case Types.DOUBLE:
@@ -800,7 +800,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));
       }
   }
   
@@ -836,7 +836,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);
   }
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java
index c39afa34b3327e72de687a10148875f609028913..d9e09c01dd1f1b69fe10f7d2456eaeab1c6d8006 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSetMetaData.java
@@ -130,7 +130,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");
   }
@@ -189,9 +189,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
@@ -219,7 +219,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();
   }
   
   /**
@@ -246,7 +246,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
   {
     Field f = getField(column);
     if(f!=null)
-      return f.name;
+      return f.getName();
     return "field"+column;
   }
   
@@ -293,7 +293,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:
@@ -330,7 +330,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:
@@ -389,7 +389,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
    */
   public String getColumnTypeName(int column) throws SQLException
   {
-    return getField(column).getTypeName();
+    return getField(column).getPGType();
   }
   
   /**
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Statement.java
index 7ffe96a91ce84c40fe965ab7d1d015a6f7d64c05..436d815d68d06f375758a3b5701c059c6a44de0c 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/Statement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Statement.java
@@ -109,7 +109,7 @@ public class Statement extends org.postgresql.Statement implements java.sql.Stat
 	public boolean execute(String sql) throws SQLException
 	{
           if (escapeProcessing)
-	      sql = escapeSql(sql);
+              sql = escapeSQL(sql);
           result = connection.ExecSQL(sql);
           return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
 	}
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java
index 5e0f86ea35e5cb3f7658c970fc7c61a4e4ac91f1..16015b881bd8ee6f2f4852bd1abe117f69b5dc94 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java
@@ -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 
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java
index e6f8e248d079935e1e6ff223b4cb77c0863d5c4b..5b4c17d7c4e04704048bc06859b703b96150ba7e 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java
@@ -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
+  };
+
+
 }
 
 // ***********************************************************************
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
index 1b80d39f3f838034a294bf0fe056e2121d71d132..bc47bbde9c1743d98eb647ac1f32b4d3d7cce072 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java
@@ -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
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
index ad81a7c61fc4302cc2759a77b3b761948ee6855f..3449f2324bfb931f79df4077f7381b468b5b043e 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
@@ -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);
   }
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java
index 7e38236552a865718933f6c530c4164d58c0d071..5d878b149e43223149d685bc995878520a4cf885 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSetMetaData.java
@@ -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();
   }
   
   /**