[jOOQ/jOOQ#11025] Fix this also for MySQL

This commit is contained in:
Lukas Eder 2020-11-25 11:08:34 +01:00
parent 7a4cb3d0ea
commit 5a795588cd
6 changed files with 24 additions and 81 deletions

View File

@ -46,6 +46,7 @@ import static org.jooq.impl.Keywords.K_JSON;
import static org.jooq.impl.Keywords.K_KEY;
import static org.jooq.impl.Keywords.K_VALUE;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.impl.Tools.inlined;
import java.util.UUID;
@ -129,7 +130,7 @@ final class JSONEntryImpl<T> extends AbstractQueryPart implements JSONEntry<T>,
case MARIADB:
case MYSQL:
case POSTGRES:
ctx.visit(key).sql(", ").visit(value);
ctx.visit(key).sql(", ").visit(jsonCast(ctx, value));
break;
default:
@ -159,6 +160,10 @@ final class JSONEntryImpl<T> extends AbstractQueryPart implements JSONEntry<T>,
break;
// [#11025] These don't have boolean support outside of JSON
case MYSQL:
if (type.getType() == Boolean.class)
return inlined(field);

View File

@ -50,6 +50,7 @@ import static org.jooq.impl.Names.N_JSON_EXTRACT;
import static org.jooq.impl.Names.N_JSON_VALUE;
import static org.jooq.impl.SQLDataType.JSONB;
import static org.jooq.impl.Tools.castIfNeeded;
import static org.jooq.impl.Tools.inlined;
import java.util.Set;

View File

@ -38,6 +38,7 @@
package org.jooq.impl;
import static org.jooq.impl.Keywords.K_COALESCE;
import static org.jooq.impl.Tools.inlined;
import org.jooq.Context;
import org.jooq.Field;

View File

@ -1,80 +0,0 @@
/*
* 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.conf.ParamType.INLINED;
import org.jooq.Context;
import org.jooq.QueryPart;
import org.jooq.SQL;
import org.jooq.conf.ParamType;
/**
* @author Lukas Eder
*/
final class SQLInline extends AbstractQueryPart implements SQL {
/**
* Generated UID
*/
private static final long serialVersionUID = 5352233054249655126L;
private QueryPart sql;
SQLInline(QueryPart part) {
this.sql = part;
}
SQLInline(SQL sql) {
this.sql = sql;
}
@Override
public final void accept(Context<?> ctx) {
ParamType paramType = ctx.paramType();
ctx.paramType(INLINED)
.visit(sql)
.paramType(paramType);
}
@Override
public String toString() {
return sql.toString();
}
}

View File

@ -276,6 +276,7 @@ import org.jooq.UDTRecord;
import org.jooq.UpdatableRecord;
import org.jooq.XML;
import org.jooq.conf.BackslashEscaping;
import org.jooq.conf.ParamType;
import org.jooq.conf.ParseNameCase;
import org.jooq.conf.RenderDefaultNullability;
import org.jooq.conf.Settings;
@ -1960,6 +1961,20 @@ final class Tools {
return result;
}
@SuppressWarnings("serial")
static final <T> Field<T> inlined(final Field<T> field) {
return new CustomField<T>(field.getQualifiedName(), field.getDataType()) {
@Override
public void accept(Context<?> ctx) {
ParamType previous = ctx.paramType();
ctx.paramType(INLINED);
ctx.visit(field);
ctx.paramType(previous);
}
};
}
static final IllegalArgumentException indexFail(Row row, Field<?> field) {
return new IllegalArgumentException("Field (" + field + ") is not contained in Row " + row);
}

View File

@ -56,6 +56,7 @@ import static org.jooq.impl.Keywords.K_VALUE;
import static org.jooq.impl.Keywords.K_XMLTABLE;
import static org.jooq.impl.Names.N_XMLTABLE;
import static org.jooq.impl.SQLDataType.XML;
import static org.jooq.impl.Tools.inlined;
import static org.jooq.impl.Tools.visitSubquery;
import static org.jooq.impl.XMLPassingMechanism.BY_REF;
import static org.jooq.impl.XMLPassingMechanism.BY_VALUE;