summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/Field.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/Field.java')
-rw-r--r--src/interfaces/jdbc/org/postgresql/Field.java147
1 files changed, 26 insertions, 121 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/Field.java b/src/interfaces/jdbc/org/postgresql/Field.java
index 8b4dcb868e..1bbc272aa8 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);
}
+
}