[jOOQ/jOOQ#13601] Derby boolean expressions have to be wrapped in parentheses when passed to COALESCE

This commit is contained in:
Lukas Eder 2022-05-25 09:32:20 +02:00
parent e41d0d281c
commit 7cfee02d44
4 changed files with 139 additions and 2 deletions

View File

@ -0,0 +1,61 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.impl.QOM.UTransient;
/**
* @author Lukas Eder
*/
abstract class AbstractDelegateField<T> extends AbstractField<T> implements UTransient {
private Field<T> delegate;
AbstractDelegateField(Field<T> delegate) {
super(delegate.getQualifiedName(), delegate.getDataType(), delegate.getCommentPart());
this.delegate = delegate;
}
@Override
public /* non-final */ void accept(Context<?> ctx) {
ctx.visit(delegate);
}
}

View File

@ -78,6 +78,14 @@ final class Coalesce<T> extends AbstractField<T> implements QOM.Coalesce<T> {
case DERBY: {
// [#13601] Workaround for https://issues.apache.org/jira/browse/DERBY-7139
ctx.visit(DSL.function(N_COALESCE, getDataType(),
Tools.map(fields, f -> f.getType() == Boolean.class ? new ParenthesisedField<>(f) : f, Field[]::new)
));
break;
}
default: {
ctx.visit(DSL.function(N_COALESCE, getDataType(), fields));
break;

View File

@ -103,6 +103,9 @@ implements
case DERBY:
return false;
@ -116,7 +119,6 @@ implements
case CUBRID:
case DERBY:
case FIREBIRD:
case IGNITE:
case POSTGRES:
@ -162,6 +164,10 @@ implements
case DERBY:
ctx.visit(DSL.coalesce(value, defaultValue));
break;
@ -176,7 +182,6 @@ implements
case CUBRID:
case DERBY:
case FIREBIRD:
case IGNITE:
case POSTGRES:

View File

@ -0,0 +1,63 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import org.jooq.Context;
import org.jooq.Field;
/**
* @author Lukas Eder
*/
final class ParenthesisedField<T> extends AbstractDelegateField<T> {
ParenthesisedField(Field<T> delegate) {
super(delegate);
}
@Override
final boolean parenthesised(Context<?> ctx) {
return true;
}
@Override
public final void accept(Context<?> ctx) {
ctx.sql('(');
super.accept(ctx);
ctx.sql(')');
}
}