[jOOQ/jOOQ#11958] BOOL_AND() and BOOL_OR() emulation does not correctly implement FILTER clause

This commit is contained in:
Lukas Eder 2021-06-03 12:13:57 +02:00
parent 16da30bbfd
commit 178b844fe3
4 changed files with 9 additions and 14 deletions

View File

@ -360,6 +360,10 @@ implements
return this;
}
final Condition f(Condition c) {
return filter != null ? filter.and(c) : c;
}
@SuppressWarnings("unchecked")
final <U> Field<U> fon(AggregateFunction<U> function) {
return DSL.nullif(fo(function), (Field<U>) zero());

View File

@ -254,8 +254,7 @@ extends
private final <N extends Number> Condition bitCheck(Field<N> field, N mask) {
// [#11956] TODO: Potentially refactor this to use GETBIT()
Condition c = DSL.bitAnd(field, inline(mask)).eq(inline(mask));
return filter != null ? filter.and(c) : c;
return f(DSL.bitAnd(field, inline(mask)).eq(inline(mask)));
}
@Override

View File

@ -87,12 +87,8 @@ final class BoolAnd extends DefaultAggregateFunction<Boolean> {
@Override
public final void accept(Context<?> ctx) {
if (EMULATE.contains(ctx.dialect())) {
ctx.visit(DSL.field(DSL.field("{0}", Integer.class, CustomQueryPart.of(c -> {
c.visit(DSL.min(DSL.when(condition, one()).otherwise(zero())));
acceptOverClause(c);
})).eq(one())));
}
if (EMULATE.contains(ctx.dialect()))
ctx.visit(fo(DSL.min(DSL.when(condition, one()).otherwise(zero()))).eq(one()));
else
super.accept(ctx);
}

View File

@ -112,12 +112,8 @@ final class BoolOr extends DefaultAggregateFunction<Boolean> {
@Override
public final void accept(Context<?> ctx) {
if (EMULATE.contains(ctx.dialect())) {
ctx.visit(DSL.field(DSL.field("{0}", Integer.class, CustomQueryPart.of(c -> {
c.visit(DSL.max(DSL.when(condition, one()).otherwise(zero())));
acceptOverClause(c);
})).eq(one())));
}
if (EMULATE.contains(ctx.dialect()))
ctx.visit(fo(DSL.max(DSL.when(condition, one()).otherwise(zero()))).eq(one()));
else
super.accept(ctx);
}