[jOOQ/jOOQ#10060] Emulate JSON_ARRAYAGG() in older MariaDB versions
This commit is contained in:
parent
09bf049e6d
commit
fe4a29bd74
@ -40,6 +40,7 @@ package org.jooq;
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
import static org.jooq.SQLDialect.MARIADB;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
|
||||
@ -59,12 +60,12 @@ public interface JSONArrayAggOrderByStep<J> extends JSONArrayAggNullStep<J> {
|
||||
/**
|
||||
* Add an <code>ORDER BY</code> clause to the function.
|
||||
*/
|
||||
@Support({ H2, POSTGRES })
|
||||
@Support({ H2, MARIADB, POSTGRES })
|
||||
JSONArrayAggNullStep<J> orderBy(OrderField<?>... fields);
|
||||
|
||||
/**
|
||||
* Add an <code>ORDER BY</code> clause to the function.
|
||||
*/
|
||||
@Support({ H2, POSTGRES })
|
||||
@Support({ H2, MARIADB, POSTGRES })
|
||||
JSONArrayAggNullStep<J> orderBy(Collection<? extends OrderField<?>> fields);
|
||||
}
|
||||
|
||||
@ -60,6 +60,7 @@ import static org.jooq.SQLDialect.MARIADB;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
// ...
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.DSL.groupConcat;
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.JSONNullClause.ABSENT_ON_NULL;
|
||||
import static org.jooq.impl.JSONNullClause.NULL_ON_NULL;
|
||||
import static org.jooq.impl.JSONObject.acceptJSONNullClause;
|
||||
@ -77,6 +79,19 @@ implements JSONArrayAggOrderByStep<J> {
|
||||
@Override
|
||||
public void accept(Context<?> ctx) {
|
||||
switch (ctx.family()) {
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
|
||||
// Workaround for https://jira.mariadb.org/browse/MDEV-21914
|
||||
if (!Tools.isEmpty(withinGroupOrderBy))
|
||||
ctx.visit(DSL.concat(inline('['), groupConcat(arguments.get(0)).orderBy(withinGroupOrderBy), inline(']')));
|
||||
|
||||
// Workaround for https://jira.mariadb.org/browse/MDEV-21912
|
||||
else
|
||||
ctx.visit(DSL.concat(inline('['), groupConcat(arguments.get(0)), inline(']')));
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -95,15 +110,19 @@ implements JSONArrayAggOrderByStep<J> {
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.visit(N_JSON_ARRAYAGG).sql('(');
|
||||
ctx.visit(arguments.get(0));
|
||||
acceptOrderBy(ctx);
|
||||
acceptJSONNullClause(ctx, nullClause);
|
||||
ctx.sql(')');
|
||||
acceptStandard(ctx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private final void acceptStandard(Context<?> ctx) {
|
||||
ctx.visit(N_JSON_ARRAYAGG).sql('(');
|
||||
ctx.visit(arguments.get(0));
|
||||
acceptOrderBy(ctx);
|
||||
acceptJSONNullClause(ctx, nullClause);
|
||||
ctx.sql(')');
|
||||
}
|
||||
|
||||
@Override
|
||||
public final JSONArrayAgg<J> nullOnNull() {
|
||||
nullClause = NULL_ON_NULL;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user