[jOOQ/jOOQ#9483] ojdbc's DatabaseMetaData::getTables returns TABLE

Instead of clearly indicating that something is a materialized view...
This commit is contained in:
Lukas Eder 2023-09-19 10:47:47 +02:00
parent 8e83af8c8b
commit 477aeba7eb
2 changed files with 18 additions and 11 deletions

View File

@ -64,6 +64,8 @@ import static org.jooq.SQLDialect.SQLITE;
import static org.jooq.SQLDialect.TRINO;
import static org.jooq.SQLDialect.YUGABYTEDB;
import static org.jooq.TableOptions.TableType.MATERIALIZED_VIEW;
import static org.jooq.TableOptions.TableType.TABLE;
import static org.jooq.TableOptions.TableType.VIEW;
import static org.jooq.impl.AbstractNamed.findIgnoreCase;
import static org.jooq.impl.DSL.comment;
import static org.jooq.impl.DSL.condition;
@ -710,8 +712,8 @@ final class MetaImpl extends AbstractMeta {
Tools.apply(v.get(0).get(3, String.class), s ->
s.toLowerCase().startsWith("create")
? s
: (type == MATERIALIZED_VIEW ? "create materialized view " : "create view ")
+ dsl().render(name(k.get(2, String.class))) + " as " + s
: (type == VIEW ? "create view " : "create materialized view ")
+ dsl().render(name(k.get(2, String.class))) + " as " + s
)
));
}
@ -816,14 +818,19 @@ final class MetaImpl extends AbstractMeta {
};
private static final TableOptions tableOption(DSLContext ctx, MetaSchema schema, String tableName, TableType tableType) {
if (tableType.isView()) {
String sql = M_SOURCES(ctx.dialect());
String sql = M_SOURCES(ctx.dialect());
if (sql != null)
if (tableType == MATERIALIZED_VIEW)
return TableOptions.materializedView(schema.source(tableType, tableName));
else
return TableOptions.view(schema.source(tableType, tableName));
if (sql != null) {
if (tableType == MATERIALIZED_VIEW)
return TableOptions.materializedView(schema.source(tableType, tableName));
else if (tableType == VIEW);
return TableOptions.view(schema.source(tableType, tableName));
}
return TableOptions.of(tableType);

View File

@ -260,10 +260,10 @@ final class MetaSQL {
M_SOURCES.put(HSQLDB, "select INFORMATION_SCHEMA.VIEWS.TABLE_CATALOG, INFORMATION_SCHEMA.VIEWS.TABLE_SCHEMA, INFORMATION_SCHEMA.VIEWS.TABLE_NAME, INFORMATION_SCHEMA.VIEWS.VIEW_DEFINITION from INFORMATION_SCHEMA.VIEWS where INFORMATION_SCHEMA.VIEWS.TABLE_SCHEMA in (cast(? as varchar(128))) order by INFORMATION_SCHEMA.VIEWS.TABLE_SCHEMA, INFORMATION_SCHEMA.VIEWS.TABLE_NAME");
M_SOURCES.put(MARIADB, "select information_schema.VIEWS.TABLE_CATALOG, information_schema.VIEWS.TABLE_SCHEMA, information_schema.VIEWS.TABLE_NAME, case when lower(information_schema.VIEWS.VIEW_DEFINITION) like 'create%' then information_schema.VIEWS.VIEW_DEFINITION else concat(concat(concat('create view `', information_schema.VIEWS.TABLE_NAME), '` as '), information_schema.VIEWS.VIEW_DEFINITION) end as VIEW_DEFINITION from information_schema.VIEWS where information_schema.VIEWS.TABLE_SCHEMA in (?) order by information_schema.VIEWS.TABLE_SCHEMA, information_schema.VIEWS.TABLE_NAME");
M_SOURCES.put(MYSQL, "select information_schema.VIEWS.TABLE_CATALOG, information_schema.VIEWS.TABLE_SCHEMA, information_schema.VIEWS.TABLE_NAME, case when lower(information_schema.VIEWS.VIEW_DEFINITION) like 'create%' then information_schema.VIEWS.VIEW_DEFINITION else concat(concat(concat('create view `', information_schema.VIEWS.TABLE_NAME), '` as '), information_schema.VIEWS.VIEW_DEFINITION) end as VIEW_DEFINITION from information_schema.VIEWS where information_schema.VIEWS.TABLE_SCHEMA in (?) order by information_schema.VIEWS.TABLE_SCHEMA, information_schema.VIEWS.TABLE_NAME");
M_SOURCES.put(POSTGRES, "select current_database(), alias_87241969.nspname, pg_catalog.pg_class.relname, (((case when pg_catalog.pg_class.relkind = 'm' then 'create materialized view \"' else 'create view \"' end || pg_catalog.pg_class.relname) || '\" as ') || pg_get_viewdef(pg_catalog.pg_class.oid)) from (pg_catalog.pg_class join pg_catalog.pg_namespace as alias_87241969 on pg_catalog.pg_class.relnamespace = alias_87241969.oid) where (pg_catalog.pg_class.relkind in ('v', 'm') and alias_87241969.nspname in (?)) order by 1, 2, 3");
M_SOURCES.put(POSTGRES, "select current_database(), alias_5049504.nspname, c.relname, (((case when c.relkind = 'm' then 'create materialized view \"' else 'create view \"' end || c.relname) || '\" as ') || pg_get_viewdef(c.oid)) from (pg_catalog.pg_class as c join pg_catalog.pg_namespace as alias_5049504 on c.relnamespace = alias_5049504.oid) where (c.relkind in ('v', 'm') and alias_5049504.nspname in (?)) order by 1, 2, 3");
M_SOURCES.put(SQLITE, "select null as catalog, null as schema, sqlite_master.name, sqlite_master.sql from sqlite_master order by sqlite_master.name");
M_SOURCES.put(TRINO, "select '' TABLE_CATALOG, INFORMATION_SCHEMA.VIEWS.TABLE_SCHEMA, INFORMATION_SCHEMA.VIEWS.TABLE_NAME, case when lower(INFORMATION_SCHEMA.VIEWS.VIEW_DEFINITION) like 'create%' then INFORMATION_SCHEMA.VIEWS.VIEW_DEFINITION else ((('create view \"' || INFORMATION_SCHEMA.VIEWS.TABLE_NAME) || '\" as ') || INFORMATION_SCHEMA.VIEWS.VIEW_DEFINITION) end VIEW_DEFINITION from INFORMATION_SCHEMA.VIEWS where INFORMATION_SCHEMA.VIEWS.TABLE_SCHEMA in (?) order by INFORMATION_SCHEMA.VIEWS.TABLE_SCHEMA, INFORMATION_SCHEMA.VIEWS.TABLE_NAME");
M_SOURCES.put(YUGABYTEDB, "select current_database(), alias_87241969.nspname, pg_catalog.pg_class.relname, (((case when pg_catalog.pg_class.relkind = 'm' then 'create materialized view \"' else 'create view \"' end || pg_catalog.pg_class.relname) || '\" as ') || pg_get_viewdef(pg_catalog.pg_class.oid)) from (pg_catalog.pg_class join pg_catalog.pg_namespace as alias_87241969 on pg_catalog.pg_class.relnamespace = alias_87241969.oid) where (pg_catalog.pg_class.relkind in ('v', 'm') and alias_87241969.nspname in (?)) order by 1, 2, 3");
M_SOURCES.put(YUGABYTEDB, "select current_database(), alias_5049504.nspname, c.relname, (((case when c.relkind = 'm' then 'create materialized view \"' else 'create view \"' end || c.relname) || '\" as ') || pg_get_viewdef(c.oid)) from (pg_catalog.pg_class as c join pg_catalog.pg_namespace as alias_5049504 on c.relnamespace = alias_5049504.oid) where (c.relkind in ('v', 'm') and alias_5049504.nspname in (?)) order by 1, 2, 3");