Skip to content

Commit 29a877b

Browse files
committed
Fix for Bug#118938 (Bug#38396227), DatabaseMetaDataInformationSchema#getSchemas has a bug.
Change-Id: I23c758838c6ab471ed6edcf17362fa8a68e327b1
1 parent 75ac12b commit 29a877b

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 9.5.0
55

6+
- Fix for Bug#118938 (Bug#38396227), DatabaseMetaDataInformationSchema#getSchemas has a bug.
7+
68
- Fix for Bug#99292 (Bug#31195955), Contribution: Support Windows time zone \'Coordinated Universal Time\'.
79
Thanks to Frédéric Barrière for his contribution.
810

src/main/user-impl/java/com/mysql/cj/jdbc/DatabaseMetaDataInformationSchema.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ public ResultSet getCatalogs() throws SQLException {
310310
if (databaseTermValue() != DatabaseTerm.CATALOG) {
311311
query.append(" WHERE FALSE");
312312
}
313+
query.append(" ORDER BY TABLE_CAT");
313314
ResultSet rs = stmt.executeQuery(query.toString());
314315

315316
((com.mysql.cj.jdbc.result.ResultSetInternalMethods) rs).getColumnDefinition().setFields(createCatalogsFields());
@@ -936,7 +937,7 @@ public ResultSet getProcedures(String catalog, String schemaPattern, String proc
936937

937938
@Override
938939
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
939-
final String dbFromTerm = chooseDatabaseTerm(catalog, schemaPattern);
940+
final String dbFromTerm = chooseDatabaseTerm(null, schemaPattern);
940941
final String dbFilter = normalizeIdentifierQuoting(dbFromTerm);
941942

942943
StringBuilder query = new StringBuilder("SELECT");
@@ -945,6 +946,7 @@ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLExce
945946
query.append(" FROM INFORMATION_SCHEMA.SCHEMATA");
946947
query.append(chooseBasedOnDatabaseTerm(() -> " WHERE FALSE",
947948
() -> dbFilter == null ? "" : StringUtils.hasWildcards(dbFilter) ? " WHERE SCHEMA_NAME LIKE ?" : " WHERE SCHEMA_NAME = ?"));
949+
query.append(" ORDER BY TABLE_CATALOG, TABLE_SCHEM");
948950

949951
try (PreparedStatement pStmt = prepareMetaDataSafeStatement(query.toString())) {
950952
if (dbFilter != null) {

src/test/java/testsuite/regression/MetaDataRegressionTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package testsuite.regression;
2222

23+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2324
import static org.junit.jupiter.api.Assertions.assertEquals;
2425
import static org.junit.jupiter.api.Assertions.assertFalse;
2526
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -6037,4 +6038,28 @@ public void testBug98620() throws Exception {
60376038
} while (useIS = !useIS);
60386039
}
60396040

6041+
/**
6042+
* Tests fix for Bug#118938 (Bug#38396227), DatabaseMetaDataInformationSchema#getSchemas has a bug.
6043+
*
6044+
* @throws Exception
6045+
*/
6046+
@Test
6047+
void testBug118938() throws Exception {
6048+
boolean useIS = false;
6049+
do {
6050+
for (DatabaseTerm dbt : DatabaseTerm.values()) {
6051+
Properties props = new Properties();
6052+
props.setProperty(PropertyKey.useInformationSchema.getKeyName(), Boolean.toString(useIS));
6053+
props.setProperty(PropertyKey.databaseTerm.getKeyName(), dbt.toString());
6054+
6055+
assertDoesNotThrow(() -> {
6056+
try (Connection testConn = getConnectionWithProps(props)) {
6057+
DatabaseMetaData dbmd = testConn.getMetaData();
6058+
dbmd.getSchemas("%", "%");
6059+
}
6060+
}, "DatabaseMetaData.getSchemas should not throw for DatabaseTerm: " + dbt);
6061+
}
6062+
} while (useIS = !useIS);
6063+
}
6064+
60406065
}

0 commit comments

Comments
 (0)