diff --git a/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java b/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java index 8145c2748..d502f9fdf 100644 --- a/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java +++ b/src/main/java/org/mariadb/jdbc/DatabaseMetaData.java @@ -733,11 +733,13 @@ public ResultSet getTables( + (conf.useCatalogTerm() == CatalogTerm.UseCatalog ? "TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM," : "TABLE_CATALOG TABLE_CAT, TABLE_SCHEMA TABLE_SCHEM,") - + " TABLE_NAME, IF(TABLE_TYPE='BASE" - + " TABLE' or TABLE_TYPE='SYSTEM VERSIONED', 'TABLE', IF(TABLE_TYPE='TEMPORARY'," - + " 'LOCAL TEMPORARY', TABLE_TYPE)) as TABLE_TYPE, TABLE_COMMENT REMARKS, NULL" - + " TYPE_CAT, NULL TYPE_SCHEM, NULL TYPE_NAME, NULL SELF_REFERENCING_COL_NAME, " - + " NULL REF_GENERATION FROM INFORMATION_SCHEMA.TABLES"); + + " TABLE_NAME, IF(TABLE_SCHEMA IN ('mysql', 'performance_schema', 'sys')," + + " IF(TABLE_TYPE='BASE TABLE', 'SYSTEM TABLE', IF(TABLE_TYPE='VIEW', 'SYSTEM" + + " VIEW', TABLE_TYPE)), IF(TABLE_TYPE='BASE TABLE' or TABLE_TYPE='SYSTEM" + + " VERSIONED', 'TABLE', IF(TABLE_TYPE='TEMPORARY', 'LOCAL TEMPORARY'," + + " TABLE_TYPE))) as TABLE_TYPE, TABLE_COMMENT REMARKS, NULL TYPE_CAT, NULL" + + " TYPE_SCHEM, NULL TYPE_NAME, NULL SELF_REFERENCING_COL_NAME, NULL" + + " REF_GENERATION FROM INFORMATION_SCHEMA.TABLES"); String database = conf.useCatalogTerm() == CatalogTerm.UseCatalog ? catalog : schemaPattern; boolean firstCondition = databaseCond( diff --git a/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java b/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java index 3c5d542c9..4c63ee650 100644 --- a/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java @@ -870,6 +870,22 @@ public void testGetTables() throws SQLException { assertTrue(rs.next()); } + @Test + public void testGetSystemTables() throws SQLException { + DatabaseMetaData dbmd = sharedConn.getMetaData(); + checkSystemRes(dbmd.getTables("mysql", null, null, null)); + checkSystemRes(dbmd.getTables("sys", null, null, null)); + checkSystemRes(dbmd.getTables("performance_schema", null, null, null)); + } + + private void checkSystemRes(ResultSet rs) throws SQLException { + while (rs.next()) { + String tableType = rs.getString("TABLE_TYPE"); + if (!tableType.matches("(SYSTEM VIEW|SYSTEM TABLE)")) + throw new SQLException("Must have System type, but was " + tableType); + } + } + @Test public void testGetTables2() throws SQLException { DatabaseMetaData dbmd = sharedConn.getMetaData();