Merge branch '6.2.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.jdbc.core.simple;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -143,6 +145,52 @@ class JdbcClientIntegrationTests {
|
||||
assertUser(expectedId, firstName, lastName);
|
||||
}
|
||||
|
||||
@Test // gh-34768
|
||||
void selectWithReusedNamedParameter() {
|
||||
this.jdbcClient.sql(INSERT_WITH_JDBC_PARAMS).params("John", "John").update();
|
||||
this.jdbcClient.sql(INSERT_WITH_JDBC_PARAMS).params("John", "Smith").update();
|
||||
this.jdbcClient.sql(INSERT_WITH_JDBC_PARAMS).params("Smith", "Smith").update();
|
||||
assertNumUsers(4);
|
||||
|
||||
String sql = """
|
||||
select * from users
|
||||
where
|
||||
first_name in ('Bogus', :name) or
|
||||
last_name in (:name, 'Bogus')
|
||||
order by last_name
|
||||
""";
|
||||
|
||||
List<User> users = this.jdbcClient.sql(sql)
|
||||
.param("name", "John")
|
||||
.query(User.class)
|
||||
.list();
|
||||
|
||||
assertThat(users).containsExactly(new User(2, "John", "John"), new User(3, "John", "Smith"));
|
||||
}
|
||||
|
||||
@Test // gh-34768
|
||||
void selectWithReusedNamedParameterList() {
|
||||
this.jdbcClient.sql(INSERT_WITH_JDBC_PARAMS).params("John", "John").update();
|
||||
this.jdbcClient.sql(INSERT_WITH_JDBC_PARAMS).params("John", "Smith").update();
|
||||
this.jdbcClient.sql(INSERT_WITH_JDBC_PARAMS).params("Smith", "Smith").update();
|
||||
assertNumUsers(4);
|
||||
|
||||
String sql = """
|
||||
select * from users
|
||||
where
|
||||
first_name in (:names) or
|
||||
last_name in (:names)
|
||||
order by last_name
|
||||
""";
|
||||
|
||||
List<User> users = this.jdbcClient.sql(sql)
|
||||
.param("names", List.of("John", "Bogus"))
|
||||
.query(User.class)
|
||||
.list();
|
||||
|
||||
assertThat(users).containsExactly(new User(2, "John", "John"), new User(3, "John", "Smith"));
|
||||
}
|
||||
|
||||
|
||||
private void assertNumUsers(long count) {
|
||||
long numUsers = this.jdbcClient.sql("select count(id) from users").query(Long.class).single();
|
||||
|
||||
Reference in New Issue
Block a user