Fix for DatabaseMetaData.getIndexInfo() - Mailing list pgsql-jdbc

From Barry Lind
Subject Fix for DatabaseMetaData.getIndexInfo()
Date
Msg-id 3BCC9E78.6050808@xythos.com
Whole thread Raw
List pgsql-jdbc
Attached is a proposed fix for a bug in DatabaseMetaData.getIndexInfo().
  This fixes a bug reported by tom_falconer@lineone.net.  On Sept 7th,
he sent a test case to the list demonstrating the bug.  His test case
now works successfully with this patch.  If no one has any objections to
this patch, I will apply it in a couple of days.

thanks,
--Barry
*** ./org/postgresql/jdbc1/DatabaseMetaData.java.orig    Tue Oct 16 13:18:21 2001
--- ./org/postgresql/jdbc1/DatabaseMetaData.java    Tue Oct 16 13:30:53 2001
***************
*** 2713,2719 ****
                  "a.amname, " +
                  "x.indkey, " +
                  "c.reltuples, " +
!                 "c.relpages " +
                  "FROM pg_index x, pg_class c, pg_class i, pg_am a " +
                  "WHERE ((c.relname = '" + tableName.toLowerCase() + "') " +
                  " AND (c.oid = x.indrelid) " +
--- 2713,2720 ----
                  "a.amname, " +
                  "x.indkey, " +
                  "c.reltuples, " +
!                 "c.relpages, " +
!                                 "x.indexrelid " +
                  "FROM pg_index x, pg_class c, pg_class i, pg_am a " +
                  "WHERE ((c.relname = '" + tableName.toLowerCase() + "') " +
                  " AND (c.oid = x.indrelid) " +
***************
*** 2747,2753 ****
                  Integer.toString(tableIndexHashed).getBytes() :
                  Integer.toString(tableIndexOther).getBytes();
              tuple[7] = Integer.toString(i + 1).getBytes();
!             java.sql.ResultSet columnNameRS = connection.ExecSQL("select a.attname FROM pg_attribute a, pg_class c
WHERE(a.attnum = " + columnOrdinals[i] + ") AND (a.attrelid = " + r.getInt(8) + ")"); 
              columnNameRS.next();
              tuple[8] = columnNameRS.getBytes(1);
              tuple[9] = null;  // sort sequence ???
--- 2748,2754 ----
                  Integer.toString(tableIndexHashed).getBytes() :
                  Integer.toString(tableIndexOther).getBytes();
              tuple[7] = Integer.toString(i + 1).getBytes();
!             java.sql.ResultSet columnNameRS = connection.ExecSQL("select a.attname FROM pg_attribute a WHERE
(a.attnum= " + columnOrdinals[i] + ") AND (a.attrelid = " + r.getInt(9) + ")"); 
              columnNameRS.next();
              tuple[8] = columnNameRS.getBytes(1);
              tuple[9] = null;  // sort sequence ???
*** ./org/postgresql/jdbc2/DatabaseMetaData.java.orig    Tue Oct 16 13:17:13 2001
--- ./org/postgresql/jdbc2/DatabaseMetaData.java    Tue Oct 16 13:31:54 2001
***************
*** 2716,2722 ****
                  "a.amname, " +
                  "x.indkey, " +
                  "c.reltuples, " +
!                 "c.relpages " +
                  "FROM pg_index x, pg_class c, pg_class i, pg_am a " +
                  "WHERE ((c.relname = '" + tableName.toLowerCase() + "') " +
                  " AND (c.oid = x.indrelid) " +
--- 2716,2723 ----
                  "a.amname, " +
                  "x.indkey, " +
                  "c.reltuples, " +
!                 "c.relpages, " +
!                                 "x.indexrelid " +
                  "FROM pg_index x, pg_class c, pg_class i, pg_am a " +
                  "WHERE ((c.relname = '" + tableName.toLowerCase() + "') " +
                  " AND (c.oid = x.indrelid) " +
***************
*** 2750,2756 ****
                  Integer.toString(tableIndexHashed).getBytes() :
                  Integer.toString(tableIndexOther).getBytes();
              tuple[7] = Integer.toString(i + 1).getBytes();
!             java.sql.ResultSet columnNameRS = connection.ExecSQL("select a.attname FROM pg_attribute a, pg_class c
WHERE(a.attnum = " + columnOrdinals[i] + ") AND (a.attrelid = " + r.getInt(8) + ")"); 
              columnNameRS.next();
              tuple[8] = columnNameRS.getBytes(1);
              tuple[9] = null;  // sort sequence ???
--- 2751,2757 ----
                  Integer.toString(tableIndexHashed).getBytes() :
                  Integer.toString(tableIndexOther).getBytes();
              tuple[7] = Integer.toString(i + 1).getBytes();
!             java.sql.ResultSet columnNameRS = connection.ExecSQL("select a.attname FROM pg_attribute a WHERE
(a.attnum= " + columnOrdinals[i] + ") AND (a.attrelid = " + r.getInt(9) + ")"); 
              columnNameRS.next();
              tuple[8] = columnNameRS.getBytes(1);
              tuple[9] = null;  // sort sequence ???

pgsql-jdbc by date:

Previous
From: "Dave Cramer"
Date:
Subject: Re: Function calls via JDBC
Next
From: "Dave Cramer"
Date:
Subject: Re: J2SE 1.4 and other patches