From 86eda279c82b79c7888558e7a2524db44c7ee108 Mon Sep 17 00:00:00 2001 From: Anton Naydenov Date: Mon, 22 Nov 2021 09:53:53 +0300 Subject: [PATCH] Support SQUARE brackets [] around NAMED parameter --- .../r2dbc/core/NamedParameterUtils.java | 3 ++- .../r2dbc/core/NamedParameterUtilsUnitTests.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java index 293d845188..724ab440bc 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java @@ -48,6 +48,7 @@ import org.springframework.util.Assert; * @author Thomas Risberg * @author Juergen Hoeller * @author Mark Paluch + * @author Anton Naydenov * @since 5.3 */ abstract class NamedParameterUtils { @@ -66,7 +67,7 @@ abstract class NamedParameterUtils { * Set of characters that qualify as parameter separators, * indicating that a parameter name in an SQL String has ended. */ - private static final String PARAMETER_SEPARATORS = "\"':&,;()|=+-*%/\\<>^"; + private static final String PARAMETER_SEPARATORS = "\"':&,;()|=+-*%/\\<>^[]"; /** * An index with separator flags per character code. diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java index f332b222e8..679bcc1fc5 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsUnitTests.java @@ -38,6 +38,7 @@ import static org.mockito.Mockito.verify; * * @author Mark Paluch * @author Jens Schauder + * @author Anton Naydenov */ public class NamedParameterUtilsUnitTests { @@ -274,6 +275,18 @@ public class NamedParameterUtilsUnitTests { assertThat(psql2.getParameterNames()).containsExactly("xxx"); } + @Test public void parseSqlStatementWithSquareBracket() { + // given + String sql = "SELECT ARRAY[:ext]"; + + // when + ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql); + + //then + assertThat(psql.getNamedParameterCount()).isEqualTo(1); + assertThat(psql.getParameterNames()).containsExactly("ext"); + } + @Test public void shouldAllowParsingMultipleUseOfParameter() {