[jOOQ/jOOQ#11481] Stop using the deprecated JSON_MERGE function in MariaDB 10.4+ and MySQL 8.0.19+
This commit is contained in:
parent
38c0acc3d4
commit
d46ba60b93
@ -39,7 +39,9 @@ package org.jooq.impl;
|
||||
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
import static org.jooq.impl.DSL.function;
|
||||
import static org.jooq.impl.DSL.groupConcat;
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
@ -52,6 +54,7 @@ import static org.jooq.impl.Names.N_JSONB_AGG;
|
||||
import static org.jooq.impl.Names.N_JSON_AGG;
|
||||
import static org.jooq.impl.Names.N_JSON_ARRAYAGG;
|
||||
import static org.jooq.impl.Names.N_JSON_MERGE;
|
||||
import static org.jooq.impl.Names.N_JSON_MERGE_PRESERVE;
|
||||
import static org.jooq.impl.Names.N_JSON_QUOTE;
|
||||
import static org.jooq.impl.SQLDataType.JSON;
|
||||
import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
@ -59,7 +62,6 @@ import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.AggregateFilterStep;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.Field;
|
||||
@ -67,8 +69,6 @@ import org.jooq.JSONArrayAggOrderByStep;
|
||||
import org.jooq.OrderField;
|
||||
import org.jooq.SQLDialect;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* The JSON array constructor.
|
||||
@ -82,8 +82,9 @@ implements JSONArrayAggOrderByStep<J> {
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 1772007627336725780L;
|
||||
static final Set<SQLDialect> EMULATE_WITH_GROUP_CONCAT = SQLDialect.supportedBy(MARIADB, MYSQL);
|
||||
private static final long serialVersionUID = 1772007627336725780L;
|
||||
static final Set<SQLDialect> EMULATE_WITH_GROUP_CONCAT = SQLDialect.supportedBy(MARIADB, MYSQL);
|
||||
static final Set<SQLDialect> SUPPORT_JSON_MERGE_PRESERVE = SQLDialect.supportedBy(MARIADB, MYSQL);
|
||||
|
||||
private JSONOnNull onNull;
|
||||
private DataType<?> returning;
|
||||
@ -99,7 +100,7 @@ implements JSONArrayAggOrderByStep<J> {
|
||||
case MYSQL: {
|
||||
// Workaround for https://jira.mariadb.org/browse/MDEV-21912,
|
||||
// https://jira.mariadb.org/browse/MDEV-21914, and other issues
|
||||
ctx.visit(N_JSON_MERGE).sql('(').visit(inline("[]")).sql(", ").visit(groupConcatEmulation(ctx)).sql(')');
|
||||
ctx.visit(SUPPORT_JSON_MERGE_PRESERVE.contains(ctx.dialect()) ? N_JSON_MERGE_PRESERVE : N_JSON_MERGE).sql('(').visit(inline("[]")).sql(", ").visit(groupConcatEmulation(ctx)).sql(')');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -189,10 +189,11 @@ implements
|
||||
|
||||
case MARIADB: {
|
||||
JSONEntry<?> first;
|
||||
Name name = JSONArrayAgg.SUPPORT_JSON_MERGE_PRESERVE.contains(ctx.dialect()) ? N_JSON_MERGE_PRESERVE : N_JSON_MERGE;
|
||||
|
||||
// Workaround for https://jira.mariadb.org/browse/MDEV-13701
|
||||
if (entries.size() > 1) {
|
||||
ctx.visit(N_JSON_MERGE).sql('(').visit(inline("{}"))
|
||||
ctx.visit(name).sql('(').visit(inline("{}"))
|
||||
.formatIndentStart();
|
||||
|
||||
for (JSONEntry<?> entry : entries)
|
||||
@ -204,7 +205,7 @@ implements
|
||||
}
|
||||
else if (!entries.isEmpty() && isJSONArray((first = entries.iterator().next()).value())) {
|
||||
ctx.visit(jsonObject(
|
||||
key(first.key()).value(DSL.field("{0}({1}, {2})", getDataType(), N_JSON_MERGE, inline("[]"), first.value()))
|
||||
key(first.key()).value(DSL.field("{0}({1}, {2})", getDataType(), name, inline("[]"), first.value()))
|
||||
));
|
||||
}
|
||||
else
|
||||
|
||||
@ -161,6 +161,7 @@ final class Names {
|
||||
static final Name N_JSON_CONTAINS_PATH = unquotedName("json_contains_path");
|
||||
static final Name N_JSON_EXTRACT = unquotedName("json_extract");
|
||||
static final Name N_JSON_MERGE = unquotedName("json_merge");
|
||||
static final Name N_JSON_MERGE_PRESERVE = unquotedName("json_merge_preserve");
|
||||
static final Name N_JSON_OBJECT = unquotedName("json_object");
|
||||
static final Name N_JSON_OBJECT_AGG = unquotedName("json_object_agg");
|
||||
static final Name N_JSON_OBJECTAGG = unquotedName("json_objectagg");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user