Bug #12541 Handling of catalog argument in DatabaseMetaData.getIndexInfo()
Submitted: 12 Aug 2005 6:58 Modified: 17 Oct 2005 19:43
Reporter: Jörgen Rydenius Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.1.10 OS:
Assigned to: Mark Matthews CPU Architecture:Any

[12 Aug 2005 6:58] Jörgen Rydenius
Description:
This is the javadoc description of argument 'catalog' to java.sql.DatabaseMetaData.getIndexInfo() in Sun JDK 1.4.2 and 1.5.0:

catalog - a catalog name; must match the catalog name as it is stored in this database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search

But looking at the 3.1.10 source code of com.mysql.jdbc.DatabaseMetaData, that is not how it is implemented:

if (catalog != null) {
  if (!catalog.equals("")) {
    databasePart = " FROM " + this.quotedId + catalog
        + this.quotedId;
  }
} else {
  if (!this.conn.getNullCatalogMeansCurrent()) {
    throw new SQLException("'catalog' parameter can not be null",
        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
  }
  catalog = this.database;
  databasePart = " FROM " + this.quotedId + this.database
      + this.quotedId;
}

Without any detailed knowledge of the code above, it looks to me that "" is treated the way null should have been -- and null is handled just wrong.

How to repeat:
Use null or "" as catalog argument to com.mysql.jdbc.DatabaseMetaData.getIndexInfo().

DatabaseMetaData dmd = ...;
dmd.getIndexInfo(null, null, <tablename>, false, true);
dmd.getIndexInfo("", null, <tablename>, false, true);

Suggested fix:
Use catalog argument according to official Sun javadoc of java.sql.DatabaseMetaData.
[12 Aug 2005 21:25] Mark Matthews
Patch is at http://lists.mysql.com/internals/28238

This should show up in this evening's nightly build after 00:00 GMT August 13th, at http://downloads.mysql.com/snapshots.php#connector-j if you want to test it.
[21 Oct 2009 2:49] pang zhigang
rs = meta.getTables(catalog, schema, "%", TYPES);
remarks = rs.getString("REMARKS");
remarks is null ?