Skip to content

Adds-test-code-related-to-issue-#34873 #34953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.r2dbc.core;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -411,6 +412,64 @@ void multipleEqualParameterReferencesBindsNullOnce() {
.containsEntry(0, Parameters.in(String.class));
}

@Test
void multipleInParameterReferencesBindsMultiple(){
List<String> userIds = List.of("user1", "user2", "user3");
String sql = """
SELECT * FROM PERSON
WHERE name IN (:ids)
GROUP BY address
UNION
SELECT * FROM PERSON
WHERE name NOT IN (:ids)
""";

BindMarkersFactory factory = BindMarkersFactory.anonymous("?");

PreparedOperation<String> operation = NamedParameterUtils.substituteNamedParameters(
sql, factory, new MapBindParameterSource(
Collections.singletonMap("ids", Parameters.in(userIds))));

assertThat(operation.toQuery()).isEqualTo(
"""
SELECT * FROM PERSON
WHERE name IN (?, ?, ?)
GROUP BY address
UNION
SELECT * FROM PERSON
WHERE name NOT IN (?, ?, ?)
""");
final String[] expectedValues = {"user1", "user2", "user3", "user1", "user2", "user3"};
final int[] bindingCount = {0};
final boolean[] isBinding = new boolean[6];
final String[] bindingValue = new String[6];
operation.bindTo(new BindTarget() {

@Override
public void bind(String identifier, Object value) {
throw new UnsupportedOperationException();
}
@Override
public void bind(int index, Object value) {
bindingCount[0]++;
isBinding[index] = true;
bindingValue[index] = (String) value;
}
@Override
public void bindNull(String identifier, Class<?> type) {
throw new UnsupportedOperationException();
}
@Override
public void bindNull(int index, Class<?> type) {
throw new UnsupportedOperationException();
}
});
assertThat(bindingCount[0]).isEqualTo(6);
assertThat(isBinding).containsExactly(true, true, true, true, true, true);
assertThat(bindingValue).containsExactly(expectedValues);
}



private static String expand(ParsedSql sql) {
return NamedParameterUtils.substituteNamedParameters(sql, INDEXED_MARKERS,
Expand Down