Skip to content

Commit 593c41f

Browse files
authored
Fix null element handling in array bind parameters (#1692)
PgParamDesc.prepare() applied the array element type's preEncoder function unconditionally to every array element, including nulls. For NUMERIC[] parameters this causes prepareNumeric() to be invoked on a null element, and the bound query never completes. Skip the preEncoder call for null elements so they are preserved as SQL NULL, matching how non-array parameters already handle null. Closes #1690 Signed-off-by: adityaanikam <adityanikam9502@gmail.com>
1 parent 862a35d commit 593c41f

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/PgParamDesc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public TupleBase prepare(TupleBase values) {
6969
Object[] array = (Object[]) val;
7070
Object[] tmp = new Object[array.length];
7171
for (int j = 0;j < array.length;j++) {
72-
tmp[j] = preparator.apply(array[j]);
72+
tmp[j] = array[j] == null ? null : preparator.apply(array[j]);
7373
}
7474
val = tmp;
7575
} else {

vertx-pg-client/src/test/java/io/vertx/tests/pgclient/data/NumericTypesExtendedCodecTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,16 @@ public void testNumericArrayToBigDecimalArrayRowConverter(TestContext ctx) {
535535
(row, index) -> row.get(BigDecimal[].class, index));
536536
}
537537

538+
@Test
539+
public void testNumericArrayToBigDecimalArrayRowConverterWithNullElement(TestContext ctx) {
540+
BigDecimal[] expected = {new BigDecimal("2.22"), null, new BigDecimal("3.33")};
541+
testGetter(ctx,
542+
"SELECT c FROM (VALUES ($1 :: NUMERIC[])) AS t (c)",
543+
Collections.singletonList(Tuple.tuple().addValue(expected)),
544+
new BigDecimal[][]{expected},
545+
(row, index) -> row.get(BigDecimal[].class, index));
546+
}
547+
538548
@Test
539549
public void testShortArray(TestContext ctx) {
540550
testGeneric(ctx,

0 commit comments

Comments
 (0)