[jOOQ/jOOQ#7290] Add DSL.chr(int)

This commit is contained in:
Lukas Eder 2021-01-13 20:27:13 +01:00
parent 4828ac5488
commit dec1e60c29
4 changed files with 157 additions and 1 deletions

View File

@ -0,0 +1,133 @@
/*
* 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 static org.jooq.impl.DSL.*;
import static org.jooq.impl.Internal.*;
import static org.jooq.impl.Keywords.*;
import static org.jooq.impl.Names.*;
import static org.jooq.impl.SQLDataType.*;
import static org.jooq.impl.Tools.*;
import static org.jooq.impl.Tools.BooleanDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.*;
import org.jooq.conf.*;
import org.jooq.impl.*;
import org.jooq.tools.*;
import java.util.*;
/**
* The <code>CHR</code> statement.
*/
@SuppressWarnings({ "rawtypes", "unused" })
final class Chr
extends
AbstractField<String>
{
private static final long serialVersionUID = 1L;
private final Field<? extends Number> number;
Chr(
Field<? extends Number> number
) {
super(
N_CHR,
allNotNull(VARCHAR, number)
);
this.number = nullSafeNotNull(number, INTEGER);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
case HSQLDB:
case MARIADB:
case MYSQL:
case SQLITE:
ctx.visit(N_CHAR).sql('(').visit(number).sql(')');
break;
case FIREBIRD:
ctx.visit(N_ASCII_CHAR).sql('(').visit(number).sql(')');
break;
default:
ctx.visit(N_CHR).sql('(').visit(number).sql(')');
break;
}
}
// -------------------------------------------------------------------------
// The Object API
// -------------------------------------------------------------------------
@Override
public boolean equals(Object that) {
if (that instanceof Chr) {
return
StringUtils.equals(number, ((Chr) that).number)
;
}
else
return super.equals(that);
}
}

View File

@ -14906,6 +14906,24 @@ public class DSL {
return new CharLength(string);
}
/**
* The <code>CHR</code> function.
*/
@NotNull
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static Field<String> chr(Number number) {
return new Chr(Tools.field(number));
}
/**
* The <code>CHR</code> function.
*/
@NotNull
@Support({ FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
public static Field<String> chr(Field<? extends Number> number) {
return new Chr(number);
}
/**
* The <code>COS</code> function.
*/

View File

@ -64,6 +64,7 @@ final class Names {
static final Name N_ARRAY_LENGTH = unquotedName("array_length");
static final Name N_ASC = unquotedName("asc");
static final Name N_ASCII = unquotedName("ascii");
static final Name N_ASCII_CHAR = unquotedName("ascii_char");
static final Name N_ASCII_VAL = unquotedName("ascii_val");
static final Name N_ASIN = unquotedName("asin");
static final Name N_ATAN = unquotedName("atan");
@ -81,8 +82,10 @@ final class Names {
static final Name N_CAST = unquotedName("cast");
static final Name N_CEIL = unquotedName("ceil");
static final Name N_CEILING = unquotedName("ceiling");
static final Name N_CHAR = unquotedName("char");
static final Name N_CHARINDEX = unquotedName("charindex");
static final Name N_CHAR_LENGTH = unquotedName("char_length");
static final Name N_CHR = unquotedName("chr");
static final Name N_CHOOSE = unquotedName("choose");
static final Name N_CLNG = unquotedName("clng");
static final Name N_COALESCE = unquotedName("coalesce");

View File

@ -88,6 +88,7 @@ import static org.jooq.impl.DSL.charLength;
import static org.jooq.impl.DSL.characterSet;
import static org.jooq.impl.DSL.check;
import static org.jooq.impl.DSL.choose;
import static org.jooq.impl.DSL.chr;
import static org.jooq.impl.DSL.coalesce;
import static org.jooq.impl.DSL.coerce;
import static org.jooq.impl.DSL.collation;
@ -361,7 +362,6 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@ -6685,6 +6685,8 @@ final class ParserContext {
return currentSchema();
else if ((parseKeywordIf("CURRENT_USER") || parseKeywordIf("CURRENT USER")) && (parseIf('(') && parse(')') || true))
return currentUser();
else if (parseFunctionNameIf("CHR") || parseFunctionNameIf("CHAR"))
return chr((Field) parseFieldParenthesised(N));
if (N.is(type))
if ((field = parseFieldCharIndexIf()) != null)