From 76a6da8a1b01e23091da65f5e167d67f5274d740 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 24 Aug 2001 16:50:18 +0000 Subject: 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 --- src/interfaces/jdbc/org/postgresql/Field.java | 147 +++++--------------------- 1 file changed, 26 insertions(+), 121 deletions(-) (limited to 'src/interfaces/jdbc/org/postgresql/Field.java') diff --git a/src/interfaces/jdbc/org/postgresql/Field.java b/src/interfaces/jdbc/org/postgresql/Field.java index 8b4dcb868e4..1bbc272aa80 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