[jOOQ/jOOQ#12189] Db2 cannot handle scalar subqueries in JSON_OBJECT in the presence of a MULTISET ad-hoc converter

This commit is contained in:
Lukas Eder 2021-07-14 16:16:56 +02:00
parent 61ca24dffa
commit f3bf1e7e73
3 changed files with 13 additions and 0 deletions

View File

@ -228,5 +228,9 @@ final class ConvertedDataType<T, U> extends AbstractDataTypeX<U> {
public final <X> DataType<X> asConvertedDataType(Converter<? super U, X> converter) {
return super.asConvertedDataType(new ChainedConverterBinding(getBinding(), converter));
}
final DataType<T> delegate() {
return delegate instanceof ConvertedDataType ? ((ConvertedDataType) delegate).delegate() : delegate;
}
}

View File

@ -63,6 +63,7 @@ import static org.jooq.impl.Names.N_JSON_QUERY;
import static org.jooq.impl.SQLDataType.VARCHAR;
import static org.jooq.impl.Tools.combine;
import static org.jooq.impl.Tools.emulateMultiset;
import static org.jooq.impl.Tools.isScalarSubquery;
import static org.jooq.impl.Tools.BooleanDataKey.DATA_MULTISET_CONTENT;
import java.util.Set;
@ -241,6 +242,9 @@ final class JSONEntryImpl<T> extends AbstractQueryPart implements JSONEntry<T>,
}
static final boolean isJSON(Scope scope, DataType<?> t) {
if (t instanceof ConvertedDataType)
t = ((ConvertedDataType<?, ?>) t).delegate();
return t.isJSON()
|| t.isRecord() && (TRUE.equals(scope.data(DATA_MULTISET_CONTENT)) && emulateMultisetWithJSON(scope))
|| t.isMultiset() && emulateMultisetWithJSON(scope);

View File

@ -5409,6 +5409,11 @@ final class Tools {
return result != null ? result : table;
}
static final boolean isScalarSubquery(Field<?> field) {
// TODO: Replace other instanceof checks by this one
return uncoerce(field) instanceof ScalarSubquery;
}
static final Field<?> uncoerce(Field<?> field) {
return field instanceof Coerce ? ((Coerce<?>) field).field : field;
}