summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/Field.java
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2001-08-17 14:45:49 +0000
committerBruce Momjian <bruce@momjian.us>2001-08-17 14:45:49 +0000
commita21c0960586f75bdab20c379804b5ee6869b91ee (patch)
tree30422edcc05d71ffe8897b1f0ff37d417ce7dcfc /src/interfaces/jdbc/org/postgresql/Field.java
parent1ebbfc150a6bf3baa7ab256018b85385c3514737 (diff)
downloadpostgresql-a21c0960586f75bdab20c379804b5ee6869b91ee.tar.gz
Thanks for your feedback (and patience). Enclosed is my third
attempt at a patch to 7.1.2 to support Array. [I think I've solved the mangled patch problem. Hotmail seems to try to format the text file, so gzipping it should solve this problem.] In this patch I've incorporated Barry's feedback. Specifically: 1) OIDs are no longer hard-coded into Array.java. In order to support this change I added a getOID(String) method to Field.java which receives a PostgreSQL field type and returns a value from java.sql.Types. I couldn't get away from using OIDs altogether because the JDBC spec for Array specifies that some methods return a ResultSet. This requires I construct Field objects, which means I need OIDs. At least this approach doesn't hard code these values. A Hashtable cache has been added to Field so that an SQL lookup isn't necessary (following the model already in Field.java). 2) Rewired the base formatting code in ResultSet.java to use 'to' methods, which are then exposed as static methods in ResultSet. These methods are used in Array to format the data without duplications in the code. 3) Artifact call to first() in ResultSet.getArray() removed. Greg Zoller
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/Field.java')
-rw-r--r--src/interfaces/jdbc/org/postgresql/Field.java37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/Field.java b/src/interfaces/jdbc/org/postgresql/Field.java
index 6450858843..8b4dcb868e 100644
--- a/src/interfaces/jdbc/org/postgresql/Field.java
+++ b/src/interfaces/jdbc/org/postgresql/Field.java
@@ -22,6 +22,8 @@ public class Field
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.
*
@@ -105,6 +107,33 @@ public class Field
}
/**
+ * 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
+ */
+ public int getOID( String type_name ) throws SQLException
+ {
+ 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;
+ }
+
+ /**
* 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
@@ -126,7 +155,9 @@ public class Field
"bool",
"date",
"time",
- "abstime","timestamp"
+ "abstime","timestamp",
+ "_bool", "_char", "_int2", "_int4", "_text", "_oid", "_varchar", "_int8",
+ "_float4", "_float8", "_abstime", "_date", "_time", "_timestamp", "_numeric"
};
/**
@@ -149,7 +180,9 @@ public class Field
Types.BIT,
Types.DATE,
Types.TIME,
- Types.TIMESTAMP,Types.TIMESTAMP
+ 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
};
/**