| Bug #118938 | DatabaseMetaDataInformationSchema#getSchemas has a bug | ||
|---|---|---|---|
| Submitted: | 4 Sep 5:38 | Modified: | 19 Oct 16:10 | 
| Reporter: | Jin Kwon | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | Connector / J | Severity: | S1 (Critical) | 
| Version: | 9.4.0 | OS: | Any | 
| Assigned to: | Filipe Silva | CPU Architecture: | Any | 
   [5 Sep 14:28]
   Filipe Silva        
  Hi Jin Kwon, Thank you for your interest in MySQL Connector/J and for taking the time to report this issue. I have verified the issue as described.
   [19 Oct 16:08]
   Edward Gilmore        
  Posted by developer: Internal. No documentation required.
   [19 Oct 16:10]
   Edward Gilmore        
  Posted by developer: Closed in error


Description: ``` StringBuilder query = new StringBuilder("SELECT"); query.append(" SCHEMA_NAME AS TABLE_SCHEM,"); // TABLE_SCHEM query.append(" CATALOG_NAME AS TABLE_CATALOG"); // TABLE_CATALOG query.append(" FROM INFORMATION_SCHEMA.SCHEMATA"); query.append(chooseBasedOnDatabaseTerm(() -> " WHERE FALSE", () -> dbFilter == null ? "" : StringUtils.hasWildcards(dbFilter) ? " WHERE SCHEMA_NAME LIKE ?" : " WHERE SCHEMA_NAME = ?")); try (PreparedStatement pStmt = prepareMetaDataSafeStatement(query.toString())) { if (dbFilter != null) { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< pStmt.setString(1, dbFilter); // <<<<<<<<<<<<<<<<<<<<< } ResultSet rs = executeMetadataQuery(pStmt); ((com.mysql.cj.jdbc.result.ResultSetInternalMethods) rs).getColumnDefinition().setFields(createSchemasFields()); return rs; } ``` When the `chooseBaseOnDatabaseTerm` evaluates ` WHERE FALSE`, The following if statement still checks `doFilter != null`, and throws ``` Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). ``` How to repeat: Make a case which evaluates ` WHERE FALSE`.