Reject iterable/collection value for positional parameter

Closes gh-31215
This commit is contained in:
Juergen Hoeller
2023-09-13 16:50:01 +02:00
parent 8f6c56fe9a
commit ae8a353041
2 changed files with 112 additions and 21 deletions

View File

@@ -106,6 +106,7 @@ final class DefaultJdbcClient implements JdbcClient {
@Override
public StatementSpec param(@Nullable Object value) {
validateIndexedParamValue(value);
this.indexedParams.add(value);
return this;
}
@@ -115,6 +116,7 @@ final class DefaultJdbcClient implements JdbcClient {
if (jdbcIndex < 1) {
throw new IllegalArgumentException("Invalid JDBC index: needs to start at 1");
}
validateIndexedParamValue(value);
int index = jdbcIndex - 1;
int size = this.indexedParams.size();
if (index < size) {
@@ -129,6 +131,14 @@ final class DefaultJdbcClient implements JdbcClient {
return this;
}
private void validateIndexedParamValue(@Nullable Object value) {
if (value instanceof Iterable) {
throw new IllegalArgumentException("Invalid positional parameter value of type Iterable (" +
value.getClass().getSimpleName() +
"): Parameter expansion is only supported with named parameters.");
}
}
@Override
public StatementSpec param(int jdbcIndex, @Nullable Object value, int sqlType) {
return param(jdbcIndex, new SqlParameterValue(sqlType, value));