SQL: Change schema calls to empty set (#41034)

As empty string has a certain meaning, the JDBC driver returns an empty
set instead for better client compatibility.

Fix #41028

(cherry picked from commit 4cbafa585b7a514eb6c156606dd516324cd3980a)
This commit is contained in:
Costin Leau 2019-04-10 13:14:18 +03:00 committed by Costin Leau
parent 4263a28039
commit 38f471ae1c
2 changed files with 9 additions and 12 deletions

View File

@ -754,22 +754,14 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
@Override @Override
public ResultSet getSchemas() throws SQLException { public ResultSet getSchemas() throws SQLException {
Object[][] data = { { EMPTY, defaultCatalog() } }; return emptySet(con.cfg, "SCHEMATA",
return memorySet(con.cfg, columnInfo("SCHEMATA", "TABLE_SCHEM",
"TABLE_SCHEM", "TABLE_CATALOG");
"TABLE_CATALOG"), data);
} }
@Override @Override
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
List<JdbcColumnInfo> info = columnInfo("SCHEMATA", return getSchemas();
"TABLE_SCHEM",
"TABLE_CATALOG");
if (!isDefaultCatalog(catalog) || !isDefaultSchema(schemaPattern)) {
return emptySet(con.cfg, info);
}
Object[][] data = { { EMPTY, defaultCatalog() } };
return memorySet(con.cfg, info, data);
} }
@Override @Override

View File

@ -104,6 +104,11 @@ public class JdbcDatabaseMetaDataTests extends ESTestCase {
testEmptySet(() -> md.getPseudoColumns(null, null, null, null)); testEmptySet(() -> md.getPseudoColumns(null, null, null, null));
} }
public void testGetSchemas() throws Exception {
testEmptySet(() -> md.getSchemas());
testEmptySet(() -> md.getSchemas(null, null));
}
private static void testEmptySet(CheckedSupplier<ResultSet, SQLException> supplier) throws SQLException { private static void testEmptySet(CheckedSupplier<ResultSet, SQLException> supplier) throws SQLException {
try (ResultSet result = supplier.get()) { try (ResultSet result = supplier.get()) {
assertNotNull(result); assertNotNull(result);