OSDN Git Service

From: Peter T Mount <patches@maidast.demon.co.uk>
authorMarc G. Fournier <scrappy@hub.org>
Sat, 18 Apr 1998 18:32:44 +0000 (18:32 +0000)
committerMarc G. Fournier <scrappy@hub.org>
Sat, 18 Apr 1998 18:32:44 +0000 (18:32 +0000)
This fixes a problem in ResultSet.getDate() when the column is NULL
(reported by Vincent Partington <Vincent.Partington@nmg.nl>)

And fixes a problem with Field's (ResultSet.getObject() was proving to be
slow as it repetedly send queries for oid -> name mapping - fixed by
creating a cache. (reported by Mario Ellebrecht <ellebrec@nads.de>)

src/interfaces/jdbc/postgresql/Connection.java
src/interfaces/jdbc/postgresql/Field.java
src/interfaces/jdbc/postgresql/ResultSet.java
src/interfaces/jdbc/postgresql/ResultSetMetaData.java
src/interfaces/jdbc/postgresql/Statement.java

index 75515da..103b4e4 100644 (file)
@@ -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
    */
index dd8918e..b39aab2 100644 (file)
@@ -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;
   }
index f8eea22..ba98bd9 100644 (file)
@@ -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();
+   }
 }
 
index fefd3ba..7a1dfbb 100644 (file)
@@ -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;
       }
index 177b818..8a3332d 100644 (file)
@@ -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();
+   }
 }