Commit a21c0960 authored by Bruce Momjian's avatar Bruce Momjian

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
parent 1ebbfc15
......@@ -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.
*
......@@ -104,6 +106,33 @@ public class Field
return sql_type;
}
/**
* 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.
......@@ -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
};
/**
......
# This is the default errors
postgresql.arr.range:The array index is out of range.
postgresql.drv.version:An internal error has occured. Please recompile the driver.
postgresql.con.auth:The authentication type {0} is not supported. Check that you have configured the pg_hba.conf file to include the client's IP address or Subnet, and that it is using an authentication scheme supported by the driver.
postgresql.con.authfail:An error occured while getting the authentication request.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment