[jOOQ/jOOQ#3679] [jOOQ/jOOQ#10540] We can't have nice things

This commit is contained in:
Lukas Eder 2020-08-27 17:17:03 +02:00
parent 02af661d77
commit 01d3752d47
2 changed files with 21 additions and 4 deletions

View File

@ -37,6 +37,8 @@
*/
package org.jooq.impl;
import static org.jooq.SQLDialect.DERBY;
import static org.jooq.impl.DSL.selectFrom;
import static org.jooq.impl.Names.N_SELECT;
import static org.jooq.impl.Tools.selectQueryImpl;
import static org.jooq.impl.Tools.visitSubquery;
@ -106,11 +108,22 @@ final class AliasedSelect<R extends Record> extends AbstractTable<R> {
@Override
public final void accept(Context<?> ctx) {
Object previous = ctx.data(DATA_SELECT_ALIASES);
SelectQueryImpl<R> q = selectQueryImpl(query);
ctx.data(DATA_SELECT_ALIASES, aliases);
visitSubquery(ctx, query);
ctx.data(DATA_SELECT_ALIASES, previous);
// [#3679] [#10540] Without standardised UNION subquery column names,
// Derby projects column indexes 1, 2, 3 as names, but
// they cannot be referenced. In that case, revert to
// actual derived table usage.
if (ctx.family() == DERBY && q != null && q.hasUnions()) {
visitSubquery(ctx, selectFrom(query.asTable(DSL.name("t"), aliases)));
}
else {
Object previous = ctx.data(DATA_SELECT_ALIASES);
ctx.data(DATA_SELECT_ALIASES, aliases);
visitSubquery(ctx, query);
ctx.data(DATA_SELECT_ALIASES, previous);
}
}
@Override // Avoid AbstractTable implementation

View File

@ -2279,6 +2279,10 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
private static final Set<SQLDialect> UNION_PARENTHESIS = SQLDialect.supportedBy(DERBY, MARIADB, MYSQL);
private static final Set<SQLDialect> UNION_PARENTHESIS_IN_DERIVED_TABLES = SQLDialect.supportedBy(DERBY);
final boolean hasUnions() {
return !unionOp.isEmpty();
}
private final boolean unionOpNesting() {
if (unionOp.size() > 1)
return true;