Re: Patches for DatabaseMetaData.java for Postgresql 7.1.3 (sorry,

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Ed Yu <ekyu(at)sc(dot)rr(dot)com>
Cc: pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Patches for DatabaseMetaData.java for Postgresql 7.1.3 (sorry,
Date: 2002-01-21 05:08:20
Message-ID: 200201210508.g0L58Ku25644@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc


This has been saved for the 7.3 release:

http://candle.pha.pa.us/cgi-bin/pgpatches2

---------------------------------------------------------------------------

Ed Yu wrote:
> This patch fixes a null pointer exception (because the return type of 'v' is
> not in the switch statement causing the variable relKind to be assigned a
> null value and a subsequent call to relKind.getBytes() throwing the
> exception) when invoking method ResultSetMetaData.getTables().
> In addition, this fix will properly recognize both the schema pattern and
> the table name pattern with both "%" and "_" SQL wildcard characters.
>
> *** DatabaseMetaData.java.orig Fri Feb 16 11:45:00 2001
> --- DatabaseMetaData.java Sat Jan 5 13:46:01 2002
> ***************
> *** 1635,1641 ****
> if(types==null)
> types = defaultTableTypes;
>
> ! if(tableNamePattern==null)
> tableNamePattern="%";
>
> // the field descriptors for the new ResultSet
> --- 1635,1644 ----
> if(types==null)
> types = defaultTableTypes;
>
> ! if((schemaPattern==null) || (schemaPattern.length()==0))
> ! schemaPattern="%";
> !
> ! if((tableNamePattern==null) || (tableNamePattern.length()==0))
> tableNamePattern="%";
>
> // the field descriptors for the new ResultSet
> ***************
> *** 1650,1656 ****
> f[4] = new Field(connection, "REMARKS", iVarcharOid, 32);
>
> // Now form the query
> ! StringBuffer sql = new StringBuffer("select relname,oid,relkind from
> pg_class where (");
> boolean notFirst=false;
> for(int i=0;i<types.length;i++) {
> for(int j=0;j<getTableTypes.length;j++)
> --- 1653,1660 ----
> f[4] = new Field(connection, "REMARKS", iVarcharOid, 32);
>
> // Now form the query
> ! StringBuffer sql = new StringBuffer(
> ! "select relname,pg_class.oid,relkind from pg_class, pg_user where
> (");
> boolean notFirst=false;
> for(int i=0;i<types.length;i++) {
> for(int j=0;j<getTableTypes.length;j++)
> ***************
> *** 1663,1673 ****
> }
>
> // Added by Stefan Andreasen <stefan(at)linux(dot)kapow(dot)dk>
> // Now take the pattern into account
> ! sql.append(") and relname like '");
> ! sql.append(tableNamePattern.toLowerCase());
> ! sql.append("'");
>
> // Now run the query
> r = connection.ExecSQL(sql.toString());
>
> --- 1667,1693 ----
> }
>
> // Added by Stefan Andreasen <stefan(at)linux(dot)kapow(dot)dk>
> + // Modified by Ed Yu <ekyu(at)asgnet(dot)psc(dot)sc(dot)edu>
> // Now take the pattern into account
> ! sql.append(") and relname");
> ! if ((tableNamePattern.indexOf("%") >= 0) ||
> ! (tableNamePattern.indexOf("_") >= 0))
> ! sql.append(" like ");
> ! else
> ! sql.append(" = ");
> ! sql.append("'" + tableNamePattern.toLowerCase() + "'");
>
> + // Added by Ed Yu <ekyu(at)asgnet(dot)psc(dot)sc(dot)edu>
> + // Now take the schemaPattern into account
> + sql.append(" and pg_class.relowner = pg_user.usesysid");
> + sql.append(" and pg_user.usename");
> + if ((schemaPattern.indexOf("%") >= 0) ||
> + (schemaPattern.indexOf("_") >= 0))
> + sql.append(" like ");
> + else
> + sql.append(" = ");
> + sql.append("'" + schemaPattern + "'");
> +
> // Now run the query
> r = connection.ExecSQL(sql.toString());
>
> ***************
> *** 1686,1691 ****
> --- 1706,1713 ----
> remarks = defaultRemarks;
> dr.close();
>
> + // JDBC definition for TABLE_TYPE - "TABLE", "VIEW", "SYSTEM TABLE",
> + // "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
> String relKind;
> switch (r.getBytes(3)[0]) {
> case 'r':
> ***************
> *** 1697,1702 ****
> --- 1719,1727 ----
> case 'S':
> relKind = "SEQUENCE";
> break;
> + case 'v':
> + relKind = "VIEW";
> + break;
> default:
> relKind = null;
> }
> ***************
> *** 1704,1710 ****
> tuple[0] = null; // Catalog name
> tuple[1] = null; // Schema name
> tuple[2] = r.getBytes(1); // Table name
> ! tuple[3] = relKind.getBytes(); // Table type
> tuple[4] = remarks; // Remarks
> v.addElement(tuple);
> }
> --- 1729,1743 ----
> tuple[0] = null; // Catalog name
> tuple[1] = null; // Schema name
> tuple[2] = r.getBytes(1); // Table name
> !
> ! // Added by Ed Yu <ekyu(at)asgnet(dot)psc(dot)sc(dot)edu>
> ! // Fix NullPointerException if return type is not handled in the
> ! // above switch statement.
> ! if (relKind==null)
> ! tuple[3] = null;
> ! else
> ! tuple[3] = relKind.getBytes(); // Table type
> !
> tuple[4] = remarks; // Remarks
> v.addElement(tuple);
> }
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Sharon Cowling 2002-01-22 02:46:00 error calling function - jdbc driver limitation?
Previous Message Bruce Momjian 2002-01-21 05:05:20 Re: Patches for ResultSetMetaData.java for Postgresql 7.1.3 (sorry,