// 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
*/
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;
}
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());
{
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();
+ }
}
return 16;
case Types.DOUBLE:
return 16;
+ case Types.VARCHAR:
+ return 0;
default:
return 0;
}
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();
+ }
}