diff --git a/src/interfaces/jdbc/postgresql/Connection.java b/src/interfaces/jdbc/postgresql/Connection.java index 75515da474e0e0d6ac38e0dbc0267c7243642ade..103b4e4b8f2f2f0ed60e9272323f29be2ab0d73e 100644 --- a/src/interfaces/jdbc/postgresql/Connection.java +++ b/src/interfaces/jdbc/postgresql/Connection.java @@ -81,6 +81,12 @@ public class Connection implements java.sql.Connection // New for 6.3, salt value for crypt authorisation private String salt; + // This is used by Field to cache oid -> names. + // It's here, because it's shared across this connection only. + // Hence it cannot be static within the Field class, because it would then + // be across all connections, which could be to different backends. + protected Hashtable fieldCache = new Hashtable(); + /** * This is the current date style of the backend */ diff --git a/src/interfaces/jdbc/postgresql/Field.java b/src/interfaces/jdbc/postgresql/Field.java index dd8918e99b74e7aee1978f7003778bf7402924c1..b39aab20c1574ec84a15c25adf15cecfe0d9fd9d 100644 --- a/src/interfaces/jdbc/postgresql/Field.java +++ b/src/interfaces/jdbc/postgresql/Field.java @@ -54,13 +54,21 @@ 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); + 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 = (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); + conn.fieldCache.put(new Integer(oid),type_name); + result.close(); + } + sql_type = getSQLType(type_name); - result.close(); } return sql_type; } diff --git a/src/interfaces/jdbc/postgresql/ResultSet.java b/src/interfaces/jdbc/postgresql/ResultSet.java index f8eea22595e9e885faec1cf047992d910d10b2ba..ba98bd97c9174f34c987b1b0bf441efd73a07b85 100644 --- a/src/interfaces/jdbc/postgresql/ResultSet.java +++ b/src/interfaces/jdbc/postgresql/ResultSet.java @@ -398,6 +398,8 @@ public class ResultSet implements java.sql.ResultSet public java.sql.Date getDate(int columnIndex) throws SQLException { String s = getString(columnIndex); + if(s==null) + return null; SimpleDateFormat df = new SimpleDateFormat(connection.getDateStyle()); try { return new java.sql.Date(df.parse(s).getTime()); @@ -856,5 +858,28 @@ public class ResultSet implements java.sql.ResultSet { return fields.length; } + + /** + * Returns the status message from the backend.<p> + * It is used internally by the driver. + * + * @return the status string from the backend + */ + public String getStatusString() + { + return status; + } + + /** + * returns the OID of a field.<p> + * It is used internally by the driver. + * + * @param field field id + * @return the oid of that field's type + */ + public int getColumnOID(int field) + { + return fields[field-1].getOID(); + } } diff --git a/src/interfaces/jdbc/postgresql/ResultSetMetaData.java b/src/interfaces/jdbc/postgresql/ResultSetMetaData.java index fefd3bafdce182830ad43506be476f07b5ac2848..7a1dfbbf26bd55407fd1113962daedb4a6440b88 100644 --- a/src/interfaces/jdbc/postgresql/ResultSetMetaData.java +++ b/src/interfaces/jdbc/postgresql/ResultSetMetaData.java @@ -265,6 +265,8 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData return 16; case Types.DOUBLE: return 16; + case Types.VARCHAR: + return 0; default: return 0; } diff --git a/src/interfaces/jdbc/postgresql/Statement.java b/src/interfaces/jdbc/postgresql/Statement.java index 177b8189f6c1e3e2db49a5999e8bf109eb450af1..8a3332da0110eef9a7db0d5fc8757a6934de63cb 100644 --- a/src/interfaces/jdbc/postgresql/Statement.java +++ b/src/interfaces/jdbc/postgresql/Statement.java @@ -299,4 +299,17 @@ public class Statement implements java.sql.Statement result = result.getNext(); return (result != null && result.reallyResultSet()); } + + /** + * Returns the status message from the current Result.<p> + * This is used internally by the driver. + * + * @return status message from backend + */ + public String getResultStatusString() + { + if(result == null) + return null; + return result.getStatusString(); + } }