Reject iterable/collection value for positional parameter
Closes gh-31215
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user