From 4f3c04ec03b609fedd435642ca3660772f5d60d7 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 3 Mar 2022 14:43:49 +0100 Subject: [PATCH] [jOOQ/jOOQ#12930] Correctly fetch top level nested records of degree 1 Top level nested records of degree 1 couldn't be fetched under some circumstances, notably when JSONB emulations tried to read ResultSet.getBytes(), but the underlying data wasn't binary compatible (the getString() method would have still worked, masking this bug so far) --- .../java/org/jooq/impl/DefaultBinding.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java index 2683ecb6f7..f35ea70bff 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java @@ -3789,11 +3789,26 @@ public class DefaultBinding implements Binding { return (Record) ctx.input().readObject(); } + @SuppressWarnings({ "unchecked", "rawtypes" }) static final R readMultiset(BindingGetResultSetContext ctx, DataType type) throws SQLException { - Result result = DefaultResultBinding.readMultiset(ctx, (AbstractRow) type.getRow(), type.getType(), - s -> s != null && (s.startsWith("[") || s.startsWith("{")) ? "[" + s + "]" : s, - s -> s != null && (s.startsWith("<")) ? "" + s + "" : s - ); + AbstractRow row = (AbstractRow) type.getRow(); + Result result; + + // [#12930] AbstractRowAsSubquery doesn't unnecessarily nest Row1 + if (row.size() == 1) { + result = new ResultImpl<>(ctx.configuration(), row); + result.add(newRecord(true, (Class) type.getRecordType(), row, ctx.configuration()).operate(r -> { + DefaultBindingGetResultSetContext c = new DefaultBindingGetResultSetContext<>(ctx.executeContext(), ctx.resultSet(), ctx.index()); + r.field(0).getBinding().get((BindingGetResultSetContext) c); + r.fromArray(c.value()); + return r; + })); + } + else + result = DefaultResultBinding.readMultiset(ctx, row, type.getType(), + s -> s != null && (s.startsWith("[") || s.startsWith("{")) ? "[" + s + "]" : s, + s -> s != null && (s.startsWith("<")) ? "" + s + "" : s + ); return isEmpty(result) ? null : result.get(0); }