From 6354644c38d1d984f064e181b276e28014eb712b Mon Sep 17 00:00:00 2001 From: Alexandr Gorshenin Date: Wed, 13 Nov 2024 18:11:30 +0000 Subject: [PATCH] Fixed InToList converter --- .../tech/ydb/jdbc/query/params/InListJdbcPrm.java | 11 +++++++++-- .../tech/ydb/jdbc/impl/YdbPreparedStatementTest.java | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/jdbc/src/main/java/tech/ydb/jdbc/query/params/InListJdbcPrm.java b/jdbc/src/main/java/tech/ydb/jdbc/query/params/InListJdbcPrm.java index 15d7c04..0e0185a 100644 --- a/jdbc/src/main/java/tech/ydb/jdbc/query/params/InListJdbcPrm.java +++ b/jdbc/src/main/java/tech/ydb/jdbc/query/params/InListJdbcPrm.java @@ -9,6 +9,7 @@ import tech.ydb.jdbc.impl.YdbTypes; import tech.ydb.table.query.Params; import tech.ydb.table.values.ListType; +import tech.ydb.table.values.OptionalType; import tech.ydb.table.values.Type; import tech.ydb.table.values.Value; import tech.ydb.table.values.VoidValue; @@ -55,15 +56,16 @@ private Value buildList() throws SQLException { return ListType.of(type.ydbType()).newValue(values); } + OptionalType optional = type.ydbType().makeOptional(); for (Item item: items) { if (item.value == NULL) { - values.add(type.nullValue()); + values.add(optional.emptyValue()); } else { values.add(item.value.makeOptional()); } } - return ListType.of(type.ydbType().makeOptional()).newValue(values); + return ListType.of(optional).newValue(values); } @@ -103,6 +105,11 @@ public void setValue(Object obj, int sqlType) throws SQLException { type = TypeDescription.of(ydbType); } + if (obj == null) { + value = NULL; + return; + } + value = type.setters().toValue(obj); } diff --git a/jdbc/src/test/java/tech/ydb/jdbc/impl/YdbPreparedStatementTest.java b/jdbc/src/test/java/tech/ydb/jdbc/impl/YdbPreparedStatementTest.java index 74d5faf..d98c73e 100644 --- a/jdbc/src/test/java/tech/ydb/jdbc/impl/YdbPreparedStatementTest.java +++ b/jdbc/src/test/java/tech/ydb/jdbc/impl/YdbPreparedStatementTest.java @@ -551,6 +551,10 @@ public void inListTest(boolean convertInToList) throws SQLException { ps.setString(2, "3"); ps.addBatch(); + ps.setInt(1, 4); + ps.setString(2, "null"); + ps.addBatch(); + ps.executeBatch(); } @@ -563,7 +567,7 @@ public void inListTest(boolean convertInToList) throws SQLException { assertResultSetCount(ps.executeQuery(), 2); ps.setInt(1, 1); - ps.setInt(2, 4); + ps.setInt(2, 5); assertResultSetCount(ps.executeQuery(), 1); ps.setInt(1, 1); @@ -591,6 +595,10 @@ public void inListTest(boolean convertInToList) throws SQLException { ps.setString(2, null); assertResultSetCount(ps.executeQuery(), 1); + ps.setString(1, null); + ps.setString(2, "2"); + assertResultSetCount(ps.executeQuery(), 0); + ps.setString(1, "1"); ps.setString(2, "1"); assertResultSetCount(ps.executeQuery(), 1);