Patches for 6.5.2
authorPeter Mount
Tue, 14 Sep 1999 05:50:44 +0000 (05:50 +0000)
committerPeter Mount
Tue, 14 Sep 1999 05:50:44 +0000 (05:50 +0000)
src/interfaces/jdbc/CHANGELOG
src/interfaces/jdbc/Makefile
src/interfaces/jdbc/makeVersion.java [deleted file]
src/interfaces/jdbc/postgresql/Connection.java
src/interfaces/jdbc/postgresql/Driver.java
src/interfaces/jdbc/postgresql/PG_Stream.java
src/interfaces/jdbc/postgresql/errors.properties
src/interfaces/jdbc/postgresql/jdbc1/Connection.java
src/interfaces/jdbc/postgresql/jdbc1/DatabaseMetaData.java
src/interfaces/jdbc/postgresql/jdbc2/Connection.java
src/interfaces/jdbc/postgresql/jdbc2/DatabaseMetaData.java

index 830e942b1402d78f4abe0f8467272f79e1716f3d..68b2aa66fad913da3921b02dc9c4ff319d7ee22a 100644 (file)
@@ -1,3 +1,18 @@
+Mon Sep 13 23:56:00 BST 1999 [email protected]
+   - PG_Stream.SendChar() optimised, increased default buffer size of
+     output stream to 8k, and introduced an 8k buffer on the input stream
+     Sverre H Huseby 
+   - Added a finalize() method to Connection class in both drivers so that
+     the connection to the backend is really closed.
+   - Due to many JVM's not returning a meaningful value for java.version
+     the decision for building the JDBC1.2 or JDBC2 driver is now a
+     compile time option.
+   - Replaced $$(cmd...) with `cmd...` in the Makefile. This should allow
+     the driver to compile when using shells other than Bash.
+
+Sun Aug  1 18:05:42 CEST 1999 [email protected]
+        - added support for getTransactionIsolation and setTransactionIsolation
+
 Sun Jun 27 12:00:00 BST 1999
    - Fixed typo in postgresql.Driver that prevented compilation
    - Implemented getTimestamp() fix submitted by Philipp Matthias Hahn
index d942767b0cef0039fe978dbbb5e8200b09b3aea2..c328689aa3d07e9ffdd43c5486c4d29abb4b3ce1 100644 (file)
@@ -4,7 +4,7 @@
 #    Makefile for Java JDBC interface
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.14 1999/06/23 05:56:17 peter Exp $
+#    $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.15 1999/09/14 05:50:27 peter Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -12,7 +12,7 @@ FIND      = find
 IDL2JAVA   = idltojava -fno-cpp -fno-tie
 JAR        = jar
 JAVA       = java
-JAVAC      = javac
+JAVAC      = javac -g
 JAVADOC        = javadoc
 RM     = rm -f
 TOUCH      = touch
@@ -22,12 +22,26 @@ TOUCH       = touch
    $(JAVAC) $<
 
 .SUFFIXES: .class .java
-.PHONY:        all clean doc examples
+.PHONY:        all clean doc examples msg
 
 # In 6.5, the all rule builds the makeVersion class which then calls make using
 # the jdbc1 or jdbc2 rules
-all:   makeVersion.class
-   make $$($(JAVA) makeVersion)
+all:   
+   @echo ------------------------------------------------------------
+   @echo Due to problems with some JVMs that dont return a meaningful
+   @echo version number, we have had to make the choice of what jdbc
+   @echo version is built as a compile time option.
+   @echo
+   @echo If you are using JDK1.1.x, you will need the JDBC1.2 driver.
+   @echo To compile, type:
+   @echo "  make jdbc1"
+   @echo
+   @echo "If you are using JDK1.2 (aka Java2) you need the JDBC2."
+   @echo To compile, type:
+   @echo "  make jdbc2"
+   @echo ------------------------------------------------------------
+
+msg:   
    @echo ------------------------------------------------------------
    @echo The JDBC driver has now been built. To make it available to
    @echo other applications, copy the postgresql.jar file to a public
@@ -107,34 +121,29 @@ OBJ_JDBC2=    postgresql/jdbc2/ResultSet.class \
        postgresql/jdbc2/ResultSetMetaData.class \
        postgresql/jdbc2/Statement.class
 
-# This rule should never occur, but will be called when makeVersion fails to
-# understand the java.version property correctly.
-jdbc0:
-   @echo
-   @echo FATAL ERROR!
-   @echo
-   @echo makeVersion has not been able to determine what version of
-   @echo the JDK you are using, and hence what version of the driver
-   @echo to compile.
-   @echo
-   @echo There are two versions available, one that conforms to the
-   @echo JDBC 1 specification, and one to the JDBC 2 specification.
-   @echo
-   @echo To build the driver for JDBC 1 (usually for JDK 1.1 thru 1.1.7)
-   @echo then type: make jdbc1
-   @echo
-   @echo To build the driver for JDBC 2 (usually for JDK 1.2 and later)
-   @echo then type: make jdbc2
-   @echo
-   @echo If you still have problems, then please email the interfaces
-   @echo or bugs lists, or better still to me direct ([email protected])
-   @echo
-
 # This rule builds the JDBC1 compliant driver
-jdbc1: $(OBJ_COMMON) $(OBJ_JDBC1) postgresql.jar
+jdbc1:
+   (echo "package postgresql;" ;\
+    echo "public class DriverClass {" ;\
+    echo "public static String connectClass=\"postgresql.jdbc1.Connection\";" ;\
+    echo "}" \
+   ) >postgresql/DriverClass.java
+   @$(MAKE) jdbc1real
+
+jdbc2real: postgresql/DriverClass.class \
+   $(OBJ_COMMON) $(OBJ_JDBC2) postgresql.jar msg
 
 # This rule builds the JDBC2 compliant driver
-jdbc2: $(OBJ_COMMON) $(OBJ_JDBC2) postgresql.jar
+jdbc2: 
+   (echo "package postgresql;" ;\
+    echo "public class DriverClass {" ;\
+    echo "public static String connectClass=\"postgresql.jdbc2.Connection\";" ;\
+    echo "}" \
+   ) >postgresql/DriverClass.java
+   @$(MAKE) jdbc2real
+
+jdbc2real: postgresql/DriverClass.class \
+   $(OBJ_COMMON) $(OBJ_JDBC2) postgresql.jar msg
 
 # If you have problems with this rule, replace the $( ) with ` ` as some
 # shells (mainly sh under Solaris) doesn't recognise $( )
@@ -143,7 +152,7 @@ jdbc2:  $(OBJ_COMMON) $(OBJ_JDBC2) postgresql.jar
 #  directory. We use this later for compiling the dual-mode driver.
 #
 postgresql.jar: $(OBJ) $(OBJ_COMMON)
-   $(JAR) -c0f $@ $$($(FIND) postgresql -name "*.class" -print) \
+   $(JAR) -c0f $@ `$(FIND) postgresql -name "*.class" -print` \
        $(wildcard postgresql/*.properties)
 
 # This rule removes any temporary and compiled files from the source tree.
diff --git a/src/interfaces/jdbc/makeVersion.java b/src/interfaces/jdbc/makeVersion.java
deleted file mode 100644 (file)
index 3badfa9..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * This class is used by the makefile to determine which version of the
- * JDK is currently in use, and if it's using JDK1.1.x then it returns JDBC1
- * and if later, it returns JDBC2
- *
- * $Id: makeVersion.java,v 1.1 1999/01/17 04:51:49 momjian Exp $
- */
-public class makeVersion
-{
-    public static void main(String[] args) {
-   String key     = "java.version";
-   String version = System.getProperty(key);
-   
-   //System.out.println(key+" = \""+version+"\"");
-   
-   // Tip: use print not println here as println breaks the make that
-   // comes with CygWin-B20.1
-   
-   if(version.startsWith("1.0")) {
-       // This will trigger the unknown rule in the makefile
-       System.out.print("jdbc0");
-   } else if(version.startsWith("1.1")) {
-       // This will trigger the building of the JDBC 1 driver
-       System.out.print("jdbc1");
-   } else {
-       // This will trigger the building of the JDBC 2 driver
-       System.out.print("jdbc2");
-   }
-    }
-}
index fc30b4dfd6c0e996ce7a0c0fcf7d986abe97e4f4..5433e336c7b7661be4825e67e9a3d2bf532936dc 100644 (file)
@@ -10,7 +10,7 @@ import postgresql.largeobject.*;
 import postgresql.util.*;
 
 /**
- * $Id: Connection.java,v 1.17 1999/05/18 23:17:15 peter Exp $
+ * $Id: Connection.java,v 1.18 1999/09/14 05:50:33 peter Exp $
  *
  * This abstract class is used by postgresql.Driver to open either the JDBC1 or
  * JDBC2 versions of the Connection class.
@@ -692,4 +692,17 @@ public abstract class Connection
      * version (from jdbc1 or jdbc2) are returned.
      */
     protected abstract java.sql.ResultSet getResultSet(postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount) throws SQLException;
+    
+    /**
+     * Overides finalize(). If called, it closes the connection.
+     *
+     * This was done at the request of Rachel Greenham
+     *  who hit a problem where multiple
+     * clients didn't close the connection, and once a fortnight enough
+     * clients were open to kill the postgres server.
+     */
+    public void finalize() throws Throwable
+    {
+   close();
+    }
 }
index 06c890309790228565f9414fe6510a120ea35257..67d06e8129dc77cd81566c1da970a38f5d929def 100644 (file)
@@ -31,9 +31,6 @@ public class Driver implements java.sql.Driver
   static final int MAJORVERSION = 6;
   static final int MINORVERSION = 5;
     
-  // Cache the version of the JDK in use
-  static String connectClass;
-    
   static 
   {
     try {
@@ -56,11 +53,27 @@ public class Driver implements java.sql.Driver
   {
       // Set the connectClass variable so that future calls will handle the correct
       // base class
-      if(System.getProperty("java.version").startsWith("1.1")) {
-     connectClass = "postgresql.jdbc1.Connection";
-      } else {
-     connectClass = "postgresql.jdbc2.Connection";
-      }
+      //if(System.getProperty("java.version").startsWith("1.1")) {
+      //connectClass = "postgresql.jdbc1.Connection";
+      //} else {
+      //connectClass = "postgresql.jdbc2.Connection";
+      //}
+      
+      // Ok, when the above code was introduced in 6.5 it's intention was to allow
+      // the driver to automatically detect which version of JDBC was being used
+      // and to detect the version of the JVM accordingly.
+      //
+      // It did this by using the java.version parameter.
+      //
+      // However, it was quickly discovered that not all JVM's returned an easily
+      // parseable version number (ie "1.2") and some don't return a value at all.
+      // The latter came from a discussion on the advanced java list.
+      //
+      // So, to solve this, I've moved the decision out of the driver, and it's now
+      // a compile time parameter.
+      //
+      // For this to work, the Makefile creates a pseudo class which contains the class
+      // name that will actually make the connection.
   }
   
   /**
@@ -96,10 +109,10 @@ public class Driver implements java.sql.Driver
     if((props = parseURL(url,info))==null)
       return null;
     
-    DriverManager.println("Using "+connectClass);
+    DriverManager.println("Using "+DriverClass.connectClass);
     
     try {
-   postgresql.Connection con = (postgresql.Connection)(Class.forName(connectClass).newInstance());
+   postgresql.Connection con = (postgresql.Connection)(Class.forName(DriverClass.connectClass).newInstance());
    con.openConnection (host(), port(), props, database(), url, this);
    return (java.sql.Connection)con;
     } catch(ClassNotFoundException ex) {
@@ -302,8 +315,10 @@ public class Driver implements java.sql.Driver
     
     // PM June 29 1997
     // This now outputs the properties only if we are logging
-    if(DriverManager.getLogStream() != null)
-      urlProps.list(DriverManager.getLogStream());
+    // PM Sep 13 1999 Commented out, as it throws a Deprecation warning
+    // when compiled under JDK1.2.
+    //if(DriverManager.getLogStream() != null)
+    //  urlProps.list(DriverManager.getLogStream());
     
     return urlProps;
     
index e2ee91ac2f76af3f379f101c033242078d9741b1..d5816b634c9f63e53d525b2937fd698ad4420dfa 100644 (file)
@@ -39,8 +39,9 @@ public class PG_Stream
     // improvement on FreeBSD machines (caused by a bug in their TCP Stack)
     connection.setTcpNoDelay(true);
     
-    pg_input = connection.getInputStream();
-    pg_output = new BufferedOutputStream(connection.getOutputStream());
+    // Buffer sizes submitted by Sverre H Huseby 
+    pg_input = new BufferedInputStream(connection.getInputStream(), 8192);
+    pg_output = new BufferedOutputStream(connection.getOutputStream(), 8192);
   }
   
   /**
@@ -51,9 +52,13 @@ public class PG_Stream
    */
   public void SendChar(int val) throws IOException
   {
-    byte b[] = new byte[1];
-    b[0] = (byte)val;
-    pg_output.write(b);
+      // Original code
+      //byte b[] = new byte[1];
+      //b[0] = (byte)val;
+      //pg_output.write(b);
+      
+      // Optimised version by Sverre H. Huseby Aug 22 1999 Applied Sep 13 1999
+      pg_output.write((byte)val);
   }
   
   /**
index 53b43c4227e3d51e75ea387d26ab43bdccef13bf..1c295ccc6d65e9f1c0da982ce489e3eb241704a8 100644 (file)
@@ -15,6 +15,7 @@ postgresql.con.refused:Connection refused. Check that the hostname and port is c
 postgresql.con.strobj:The object could not be stored. Check that any tables required have already been created in the database.
 postgresql.con.strobjex:Failed to store object - {0}
 postgresql.con.toolong:The SQL Statement is too long - {0}
+postgresql.con.isolevel:Transaction isolation level {0} is not supported.
 postgresql.con.tuple:Tuple received before MetaData.
 postgresql.con.type:Unknown Response Type {0}
 postgresql.con.user:The user property is missing. It is mandatory.
index f7c88c579a26647c1f55ae8020e7bc5a5a0cc808..7a83e6f114e476a10b90cac8443d4ee84ce16d3d 100644 (file)
@@ -17,7 +17,7 @@ import postgresql.largeobject.*;
 import postgresql.util.*;
 
 /**
- * $Id: Connection.java,v 1.2 1999/05/18 23:17:21 peter Exp $
+ * $Id: Connection.java,v 1.3 1999/09/14 05:50:39 peter Exp $
  *
  * A Connection represents a session with a specific database.  Within the
  * context of a Connection, SQL statements are executed and results are
@@ -216,7 +216,7 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
      pg_stream = null;
       }
   }
-  
+    
   /**
    * Tests to see if a Connection is closed
    *
@@ -311,9 +311,23 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
    */
   public void setTransactionIsolation(int level) throws SQLException
   {
-    throw postgresql.Driver.notImplemented();
+      String q = "SET TRANSACTION ISOLATION LEVEL";
+      
+      switch(level) {
+     
+      case java.sql.Connection.TRANSACTION_READ_COMMITTED:
+     ExecSQL(q + " READ COMMITTED");
+     return;
+     
+      case java.sql.Connection.TRANSACTION_SERIALIZABLE:
+     ExecSQL(q + " SERIALIZABLE");
+     return;
+     
+      default:
+     throw new PSQLException("postgresql.con.isolevel",new Integer(level));
+      }
   }
-  
+    
   /**
    * Get this Connection's current transaction isolation mode.
    * 
@@ -322,9 +336,18 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
    */
   public int getTransactionIsolation() throws SQLException
   {
-    return java.sql.Connection.TRANSACTION_SERIALIZABLE;
+      ExecSQL("show xactisolevel");
+      
+      SQLWarning w = getWarnings();
+      if (w != null) {
+     if (w.getMessage().indexOf("READ COMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_COMMITTED; else
+         if (w.getMessage().indexOf("READ UNCOMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED; else
+         if (w.getMessage().indexOf("REPEATABLE READ") != -1) return java.sql.Connection.TRANSACTION_REPEATABLE_READ; else
+             if (w.getMessage().indexOf("SERIALIZABLE") != -1) return java.sql.Connection.TRANSACTION_SERIALIZABLE; 
+      }
+      return java.sql.Connection.TRANSACTION_READ_COMMITTED;
   }
-  
+    
   /**
    * The first warning reported by calls on this Connection is
    * returned.
index b7e90e8768adff5cce7cc8b59f48ee79ea474740..84130f2cb46a14d0876f362fa3e03c5699a8f476 100644 (file)
@@ -179,7 +179,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
    */
   public String getDatabaseProductVersion() throws SQLException
   {
-    return ("6.4");
+    return ("6.5.2");
   }
   
   /**
@@ -1350,7 +1350,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
    */
   public int getDefaultTransactionIsolation() throws SQLException
   {
-    return Connection.TRANSACTION_SERIALIZABLE;
+    return Connection.TRANSACTION_READ_COMMITTED;
   }
   
   /**
@@ -1368,7 +1368,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
   
   /**
    * Does the database support the given transaction isolation level?
-   * We only support TRANSACTION_SERIALIZABLE
+   * We only support TRANSACTION_SERIALIZABLE and TRANSACTION_READ_COMMITTED
    * 
    * @param level the values are defined in java.sql.Connection
    * @return true if so
@@ -1377,10 +1377,11 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
    */
   public boolean supportsTransactionIsolationLevel(int level) throws SQLException
   {
-    if (level == Connection.TRANSACTION_SERIALIZABLE)
-      return true;
-    else
-      return false;
+      if (level == Connection.TRANSACTION_SERIALIZABLE ||
+     level == Connection.TRANSACTION_READ_COMMITTED)
+     return true;
+      else
+     return false;
   }
   
   /**
@@ -2151,21 +2152,19 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
   public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException
   {
     return connection.createStatement().executeQuery("SELECT " +
-                            "'' as TABLE_CAT," +
-                            "'' AS TABLE_SCHEM," +
-                            "bc.relname AS TABLE_NAME," +
-                            "ic.relname AS COLUMN_NAME," +
-                            "'1' as KEY_SEQ,"+ // -- fake it as a String for now
-                            "t.typname as PK_NAME " +
-                            " FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t " +
-                            " WHERE bc.relkind = 'r' " + //    -- not indices
-                            "  and bc.relname ~ '"+table+"'" +
-                            "  and i.indrelid = bc.oid" +
-                            "  and i.indexrelid = ic.oid" +
-                            "  and i.indkey[0] = a.attnum" +
-                            "  and i.indproc = '0'::oid" +
-                            "  and a.attrelid = bc.oid" +
-                            " ORDER BY TABLE_NAME, COLUMN_NAME;"
+                            " '' as TABLE_CAT," +
+                            " '' AS TABLE_SCHEM," +
+                            " bc.relname AS TABLE_NAME," +
+                            " a.attname AS COLUMN_NAME," +
+                            " a.attnum as KEY_SEQ," +
+                            " ic.relname as PK_NAME" +
+                            " from pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t" +
+                            " where bc.relkind = 'r'"+
+                            " and upper(bc.relname) = upper('test')" +
+                            " and i.indrelid = bc.oid" +
+                            " and i.indexrelid = ic.oid  and a.attrelid = ic.oid"+
+                            " and i.indisprimary='t'"+
+                            " order by table_name, pk_name,key_seq;"
                             );
   }
   
index 7e086435b2018fa127ce2ebc9e041f4a05430b97..32ffce81ee2902d73bcfdab6853622ac79f32f31 100644 (file)
@@ -17,7 +17,7 @@ import postgresql.largeobject.*;
 import postgresql.util.*;
 
 /**
- * $Id: Connection.java,v 1.2 1999/05/18 23:17:26 peter Exp $
+ * $Id: Connection.java,v 1.3 1999/09/14 05:50:44 peter Exp $
  *
  * A Connection represents a session with a specific database.  Within the
  * context of a Connection, SQL statements are executed and results are
@@ -216,7 +216,7 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
      pg_stream = null;
       }
   }
-  
+    
   /**
    * Tests to see if a Connection is closed
    *
@@ -311,7 +311,21 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
    */
   public void setTransactionIsolation(int level) throws SQLException
   {
-      throw postgresql.Driver.notImplemented();
+    String q = "SET TRANSACTION ISOLATION LEVEL";
+
+    switch(level) {
+
+      case java.sql.Connection.TRANSACTION_READ_COMMITTED:
+        ExecSQL(q + " READ COMMITTED");
+   return;
+      
+      case java.sql.Connection.TRANSACTION_SERIALIZABLE:
+        ExecSQL(q + " SERIALIZABLE");
+   return;
+
+      default:
+        throw new PSQLException("postgresql.con.isolevel",new Integer(level));
+    }
   }
   
   /**
@@ -322,9 +336,18 @@ public class Connection extends postgresql.Connection implements java.sql.Connec
    */
   public int getTransactionIsolation() throws SQLException
   {
-    return java.sql.Connection.TRANSACTION_SERIALIZABLE;
+      ExecSQL("show xactisolevel");
+      
+      SQLWarning w = getWarnings();
+      if (w != null) {
+     if (w.getMessage().indexOf("READ COMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_COMMITTED; else
+         if (w.getMessage().indexOf("READ UNCOMMITTED") != -1) return java.sql.Connection.TRANSACTION_READ_UNCOMMITTED; else
+         if (w.getMessage().indexOf("REPEATABLE READ") != -1) return java.sql.Connection.TRANSACTION_REPEATABLE_READ; else
+             if (w.getMessage().indexOf("SERIALIZABLE") != -1) return java.sql.Connection.TRANSACTION_SERIALIZABLE; 
+      }
+      return java.sql.Connection.TRANSACTION_READ_COMMITTED;
   }
-  
+    
   /**
    * The first warning reported by calls on this Connection is
    * returned.
index 9a73f22d81f82589652c72bca93f2f9a855a8603..b6550654efda6418dbee9f029f895af444e2e730 100644 (file)
@@ -179,7 +179,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
    */
   public String getDatabaseProductVersion() throws SQLException
   {
-    return ("6.4");
+    return ("6.5.2");
   }
   
   /**
@@ -1350,7 +1350,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
    */
   public int getDefaultTransactionIsolation() throws SQLException
   {
-    return Connection.TRANSACTION_SERIALIZABLE;
+      return Connection.TRANSACTION_READ_COMMITTED;
   }
   
   /**
@@ -1368,7 +1368,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
   
   /**
    * Does the database support the given transaction isolation level?
-   * We only support TRANSACTION_SERIALIZABLE
+   * We only support TRANSACTION_SERIALIZABLE and TRANSACTION_READ_COMMITTED
    * 
    * @param level the values are defined in java.sql.Connection
    * @return true if so
@@ -1377,7 +1377,8 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
    */
   public boolean supportsTransactionIsolationLevel(int level) throws SQLException
   {
-    if (level == Connection.TRANSACTION_SERIALIZABLE)
+    if (level == Connection.TRANSACTION_SERIALIZABLE ||
+        level == Connection.TRANSACTION_READ_COMMITTED)
       return true;
     else
       return false;
@@ -2151,21 +2152,19 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
   public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException
   {
     return connection.createStatement().executeQuery("SELECT " +
-                            "'' as TABLE_CAT," +
-                            "'' AS TABLE_SCHEM," +
-                            "bc.relname AS TABLE_NAME," +
-                            "ic.relname AS COLUMN_NAME," +
-                            "'1' as KEY_SEQ,"+ // -- fake it as a String for now
-                            "t.typname as PK_NAME " +
-                            " FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t " +
-                            " WHERE bc.relkind = 'r' " + //    -- not indices
-                            "  and bc.relname ~ '"+table+"'" +
-                            "  and i.indrelid = bc.oid" +
-                            "  and i.indexrelid = ic.oid" +
-                            "  and i.indkey[0] = a.attnum" +
-                            "  and i.indproc = '0'::oid" +
-                            "  and a.attrelid = bc.oid" +
-                            " ORDER BY TABLE_NAME, COLUMN_NAME;"
+                            " '' as TABLE_CAT," +
+                            " '' AS TABLE_SCHEM," +
+                            " bc.relname AS TABLE_NAME," +
+                            " a.attname AS COLUMN_NAME," +
+                            " a.attnum as KEY_SEQ," +
+                            " ic.relname as PK_NAME" +
+                            " from pg_class bc, pg_class ic, pg_index i, pg_attribute a, pg_type t" +
+                            " where bc.relkind = 'r'"+
+                            " and upper(bc.relname) = upper('test')" +
+                            " and i.indrelid = bc.oid" +
+                            " and i.indexrelid = ic.oid  and a.attrelid = ic.oid"+
+                            " and i.indisprimary='t'"+
+                            " order by table_name, pk_name,key_seq;"
                             );
   }