Skip to content

Commit

Permalink
[CONJ-1100] ensure DatabaseMetaData.getTables() returning mysql, perf…
Browse files Browse the repository at this point in the history
…ormance_schema and sys as system tables/views, to permit filtering only user tables/view
  • Loading branch information
rusher committed Apr 15, 2024
1 parent 5e243b1 commit 74e581b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/org/mariadb/jdbc/DatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 74e581b

Please sign in to comment.