From ba977c086c01726affcc96219a79584a11ccc78e Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Sun, 11 Jan 1998 21:14:56 +0000 Subject: Peter's Mega-Patch for JDBC... see README_6.3 for list of changes --- src/interfaces/jdbc/postgresql/Field.java | 122 +++++++++++++++++++----------- 1 file changed, 79 insertions(+), 43 deletions(-) (limited to 'src/interfaces/jdbc/postgresql/Field.java') diff --git a/src/interfaces/jdbc/postgresql/Field.java b/src/interfaces/jdbc/postgresql/Field.java index a4cc3c76e76..78553dd32eb 100644 --- a/src/interfaces/jdbc/postgresql/Field.java +++ b/src/interfaces/jdbc/postgresql/Field.java @@ -6,10 +6,8 @@ import java.util.*; import postgresql.*; /** - * postgresql.Field is a class used to describe fields in a PostgreSQL ResultSet - * - * @version 1.0 15-APR-1997 - * @author Adrian Hall + * postgresql.Field is a class used to describe fields in a PostgreSQL + * ResultSet */ public class Field { @@ -22,7 +20,7 @@ public class Field String type_name = null;// The sql type name /** - * Construct a field based on the information fed to it. + * 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 @@ -37,6 +35,14 @@ public class Field this.length = length; } + /** + * @return the oid of this Field's data type + */ + public int getOID() + { + return oid; + } + /** * the ResultSet and ResultMetaData both need to handle the SQL * type, which is gained from another query. Note that we cannot @@ -47,47 +53,77 @@ public class Field */ 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 if (type_name.equals("timestamp")) - sql_type = Types.TIMESTAMP; - else - sql_type = Types.OTHER; - } + 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(); + sql_type = getSQLType(result.getString(1)); + result.close(); + } + return sql_type; + } + + /** + * 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 + */ + public static int getSQLType(String type_name) + { + int sql_type = Types.OTHER; // default value + for(int i=0;i