Skip to content

Commit

Permalink
Fixed InToList converter (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 authored Nov 13, 2024
2 parents 3cfa744 + 6354644 commit 7b5dc3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions jdbc/src/main/java/tech/ydb/jdbc/query/params/InListJdbcPrm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7b5dc3b

Please sign in to comment.