[jOOQ/jOOQ#11672] Function formatting
improvements This includes: - [jOOQ/jOOQ#11674] Add native support for NVL2 where supported - [jOOQ/jOOQ9085] NVL2 should generate NVL2 for the DEFAULT dialect
This commit is contained in:
parent
d43fc234ef
commit
d802105da7
@ -110,7 +110,7 @@ extends
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(N_LTRIM).sql('(').visit(string).sql(')');
|
||||
ctx.visit(function(N_LTRIM, getDataType(), string));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -120,7 +120,7 @@ extends
|
||||
|
||||
|
||||
case SQLITE:
|
||||
ctx.visit(N_LTRIM).sql('(').visit(string).sql(", ").visit(characters).sql(')');
|
||||
ctx.visit(function(N_LTRIM, getDataType(), string, characters));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@ -85,8 +85,6 @@ extends
|
||||
// XXX: QueryPart API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
@ -105,7 +103,7 @@ extends
|
||||
|
||||
|
||||
|
||||
case POSTGRES:
|
||||
case POSTGRES: {
|
||||
|
||||
|
||||
|
||||
@ -114,15 +112,14 @@ extends
|
||||
|
||||
ctx.visit(N_LOG10).sql('(').visit(value).sql(')');
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ctx.visit(N_LOG10).sql('(').visit(value).sql(')');
|
||||
ctx.visit(function(N_LOG10, getDataType(), value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -140,7 +140,7 @@ extends
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(N_LPAD).sql('(').visit(string).sql(", ").visit(length).sql(", ").visit(character()).sql(')');
|
||||
ctx.visit(function(N_LPAD, getDataType(), string, length, character()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,6 +37,9 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
// ...
|
||||
import static org.jooq.impl.DSL.function;
|
||||
import static org.jooq.impl.DSL.iif;
|
||||
import static org.jooq.impl.Names.N_NVL2;
|
||||
|
||||
@ -75,16 +78,44 @@ final class Nvl2<T> extends AbstractField<T> {
|
||||
|
||||
|
||||
|
||||
case MARIADB:
|
||||
|
||||
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
ctx.visit(N_NVL2).sql('(').visit(arg1).sql(", ").visit(arg2).sql(", ").visit(arg3).sql(')');
|
||||
|
||||
|
||||
|
||||
acceptDefault(ctx);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case CUBRID:
|
||||
case DERBY:
|
||||
case FIREBIRD:
|
||||
case MYSQL:
|
||||
case POSTGRES:
|
||||
case SQLITE:
|
||||
acceptCase(ctx);
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(DSL.when(arg1.isNotNull(), arg2).otherwise(arg3));
|
||||
acceptDefault(ctx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void acceptCase(Context<?> ctx) {
|
||||
ctx.visit(DSL.when(arg1.isNotNull(), arg2).otherwise(arg3));
|
||||
}
|
||||
|
||||
private final void acceptDefault(Context<?> ctx) {
|
||||
ctx.visit(function(N_NVL2, getDataType(), arg1, arg2, arg3));
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ extends
|
||||
|
||||
if (l != null) {
|
||||
if (SUPPORT_INSERT.contains(ctx.dialect())) {
|
||||
ctx.visit(N_INSERT).sql('(').visit(in).sql(", ").visit(startIndex).sql(", ").visit(l).sql(", ").visit(placing).sql(')');
|
||||
ctx.visit(function(N_INSERT, getDataType(), in, startIndex, l, placing));
|
||||
}
|
||||
else if (NO_SUPPORT.contains(ctx.dialect())) {
|
||||
ctx.visit(
|
||||
@ -144,7 +144,7 @@ extends
|
||||
}
|
||||
else {
|
||||
if (SUPPORT_INSERT.contains(ctx.dialect())) {
|
||||
ctx.visit(N_INSERT).sql('(').visit(in).sql(", ").visit(startIndex).sql(", ").visit(DSL.length(placing)).sql(", ").visit(placing).sql(')');
|
||||
ctx.visit(function(N_INSERT, getDataType(), in, startIndex, DSL.length(placing), placing));
|
||||
}
|
||||
else if (NO_SUPPORT.contains(ctx.dialect())) {
|
||||
ctx.visit(
|
||||
|
||||
@ -110,7 +110,7 @@ extends
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(N_RTRIM).sql('(').visit(string).sql(')');
|
||||
ctx.visit(function(N_RTRIM, getDataType(), string));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -120,7 +120,7 @@ extends
|
||||
|
||||
|
||||
case SQLITE:
|
||||
ctx.visit(N_RTRIM).sql('(').visit(string).sql(", ").visit(characters).sql(')');
|
||||
ctx.visit(function(N_RTRIM, getDataType(), string, characters)));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@ -140,7 +140,7 @@ extends
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(N_RPAD).sql('(').visit(string).sql(", ").visit(length).sql(", ").visit(character()).sql(')');
|
||||
ctx.visit(function(N_RPAD, getDataType(), string, length, character()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
61
jOOQ/src/main/java/org/jooq/impl/SimpleQueryPart.java
Normal file
61
jOOQ/src/main/java/org/jooq/impl/SimpleQueryPart.java
Normal 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.OrderField;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.QueryPartInternal;
|
||||
|
||||
/**
|
||||
* A marker interface for all query parts that are capable of generating
|
||||
* "simple" SQL. This information is used mainly for formatting decisions.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
interface SimpleQueryPart extends QueryPartInternal {
|
||||
|
||||
/**
|
||||
* Whether the {@link QueryPart} really is simple.
|
||||
* <p>
|
||||
* e.g. an {@link OrderField} can be simple if its contents are also simple.
|
||||
*/
|
||||
default boolean isSimple() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -103,6 +103,7 @@ extends
|
||||
|
||||
|
||||
|
||||
|
||||
case SQLITE:
|
||||
ctx.visit(DSL.power(value, inline(0.5)));
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user