[jOOQ/jOOQ#11009] Add support for the MySQL FIELD() function
This commit is contained in:
parent
4b462d3a21
commit
db45db76cd
@ -13490,6 +13490,26 @@ public class DSL {
|
||||
// XXX Global Field and Function factory
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the MySQL <code>FIELD(expr, expr1, expr2, ...)</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
@SafeVarargs
|
||||
public static <T> Field<Integer> field(Field<T> field, T... list) {
|
||||
return field(field, Tools.fieldsArray(list, field.getDataType()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL <code>FIELD(expr, expr1, expr2, ...)</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
@SafeVarargs
|
||||
public static <T> Field<Integer> field(Field<T> field, Field<T>... list) {
|
||||
return new FieldFunction<>(field, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a {@link SelectField} in a general-purpose {@link Field}
|
||||
*/
|
||||
|
||||
@ -114,6 +114,7 @@ final class Names {
|
||||
static final Name N_EXP = unquotedName("exp");
|
||||
static final Name N_EXTRACT = unquotedName("extract");
|
||||
static final Name N_EXTRACT_DURATION = unquotedName("extract_duration");
|
||||
static final Name N_FIELD = unquotedName("field");
|
||||
static final Name N_FLASHBACK = unquotedName("flashback");
|
||||
static final Name N_FLOOR = unquotedName("floor");
|
||||
static final Name N_FUNCTION = unquotedName("function");
|
||||
|
||||
@ -9347,31 +9347,15 @@ final class ParserImpl implements Parser {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final <T, Z> Field<?> parseFieldFieldIf(ParserContext ctx) {
|
||||
private static final <T> Field<?> parseFieldFieldIf(ParserContext ctx) {
|
||||
if (parseFunctionNameIf(ctx, "FIELD")) {
|
||||
parse(ctx, '(');
|
||||
|
||||
List<Field<?>> args = new ArrayList<>();
|
||||
|
||||
args.add(parseField(ctx));
|
||||
Field<?> f1 = parseField(ctx);
|
||||
parse(ctx, ',');
|
||||
|
||||
int i = 1;
|
||||
do {
|
||||
args.add(parseField(ctx));
|
||||
args.add(inline(i++));
|
||||
}
|
||||
while (parseIf(ctx, ','));
|
||||
|
||||
args.add(inline(0));
|
||||
List<Field<?>> f2 = parseFields(ctx);
|
||||
parse(ctx, ')');
|
||||
|
||||
return DSL.decode(
|
||||
(Field<T>) args.get(0),
|
||||
(Field<T>) args.get(1),
|
||||
(Field<Z>) args.get(2),
|
||||
args.subList(3, args.size()).toArray(EMPTY_FIELD)
|
||||
);
|
||||
return DSL.field((Field<T>) f1, (Field<T>[]) f2.toArray(EMPTY_FIELD));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@ -1968,6 +1968,18 @@ final class Tools {
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static final <T> Field<T>[] fieldsArray(Object[] values, DataType<T> type) {
|
||||
if (values == null)
|
||||
return (Field<T>[]) EMPTY_FIELD;
|
||||
|
||||
Field<T>[] result = new Field[values.length];
|
||||
for (int i = 0; i < result.length; i++)
|
||||
result[i] = field(values[i], type);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static final Field<?>[] fieldsArray(Object[] values, DataType<?>[] types) {
|
||||
if (values == null || types == null)
|
||||
return EMPTY_FIELD;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user