Skip to content

Commit 6354644

Browse files
committed
Fixed InToList converter
1 parent e895734 commit 6354644

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

jdbc/src/main/java/tech/ydb/jdbc/query/params/InListJdbcPrm.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tech.ydb.jdbc.impl.YdbTypes;
1010
import tech.ydb.table.query.Params;
1111
import tech.ydb.table.values.ListType;
12+
import tech.ydb.table.values.OptionalType;
1213
import tech.ydb.table.values.Type;
1314
import tech.ydb.table.values.Value;
1415
import tech.ydb.table.values.VoidValue;
@@ -55,15 +56,16 @@ private Value<?> buildList() throws SQLException {
5556
return ListType.of(type.ydbType()).newValue(values);
5657
}
5758

59+
OptionalType optional = type.ydbType().makeOptional();
5860
for (Item item: items) {
5961
if (item.value == NULL) {
60-
values.add(type.nullValue());
62+
values.add(optional.emptyValue());
6163
} else {
6264
values.add(item.value.makeOptional());
6365
}
6466
}
6567

66-
return ListType.of(type.ydbType().makeOptional()).newValue(values);
68+
return ListType.of(optional).newValue(values);
6769

6870
}
6971

@@ -103,6 +105,11 @@ public void setValue(Object obj, int sqlType) throws SQLException {
103105
type = TypeDescription.of(ydbType);
104106
}
105107

108+
if (obj == null) {
109+
value = NULL;
110+
return;
111+
}
112+
106113
value = type.setters().toValue(obj);
107114
}
108115

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbPreparedStatementTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ public void inListTest(boolean convertInToList) throws SQLException {
551551
ps.setString(2, "3");
552552
ps.addBatch();
553553

554+
ps.setInt(1, 4);
555+
ps.setString(2, "null");
556+
ps.addBatch();
557+
554558
ps.executeBatch();
555559
}
556560

@@ -563,7 +567,7 @@ public void inListTest(boolean convertInToList) throws SQLException {
563567
assertResultSetCount(ps.executeQuery(), 2);
564568

565569
ps.setInt(1, 1);
566-
ps.setInt(2, 4);
570+
ps.setInt(2, 5);
567571
assertResultSetCount(ps.executeQuery(), 1);
568572

569573
ps.setInt(1, 1);
@@ -591,6 +595,10 @@ public void inListTest(boolean convertInToList) throws SQLException {
591595
ps.setString(2, null);
592596
assertResultSetCount(ps.executeQuery(), 1);
593597

598+
ps.setString(1, null);
599+
ps.setString(2, "2");
600+
assertResultSetCount(ps.executeQuery(), 0);
601+
594602
ps.setString(1, "1");
595603
ps.setString(2, "1");
596604
assertResultSetCount(ps.executeQuery(), 1);

0 commit comments

Comments
 (0)