Skip to content

Commit bc2895a

Browse files
committed
Support backticks for quoted identifiers in spring-r2dbc
NamedParameterUtils in spring-r2dbc now supports MySQL-style backticks for quoted identifiers for consistency with spring-jdbc. See gh-31944 Closes gh-32285
1 parent d86af57 commit bc2895a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ abstract class NamedParameterUtils {
5656
/**
5757
* Set of characters that qualify as comment or quote starting characters.
5858
*/
59-
private static final String[] START_SKIP = {"'", "\"", "--", "/*"};
59+
private static final String[] START_SKIP = {"'", "\"", "--", "/*", "`"};
6060

6161
/**
6262
* Set of characters that are the corresponding comment or quote ending characters.
6363
*/
64-
private static final String[] STOP_SKIP = {"'", "\"", "\n", "*/"};
64+
private static final String[] STOP_SKIP = {"'", "\"", "\n", "*/", "`"};
6565

6666
/**
6767
* Set of characters that qualify as parameter separators,

Diff for: spring-r2dbc/src/test/java/org/springframework/r2dbc/core/NamedParameterUtilsTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ void variableAssignmentOperator() {
251251
"SELECT /*:doo*/':foo', :xxx FROM DUAL",
252252
"SELECT ':foo'/*:doo*/, :xxx FROM DUAL",
253253
"SELECT \":foo\"\":doo\", :xxx FROM DUAL",
254+
"SELECT `:foo``:doo`, :xxx FROM DUAL"
254255
})
255256
void parseSqlStatementWithParametersInsideQuotesAndComments(String sql) {
256257
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
@@ -289,6 +290,14 @@ void namedParamMapReference() {
289290
assertThat(psql.getParameterNames()).containsExactly("headers[id]");
290291
}
291292

293+
@Test // gh-31944 / gh-32285
294+
void parseSqlStatementWithBackticks() {
295+
String sql = "select * from `tb&user` where id = :id";
296+
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
297+
assertThat(parsedSql.getParameterNames()).containsExactly("id");
298+
assertThat(expand(parsedSql)).isEqualTo("select * from `tb&user` where id = $1");
299+
}
300+
292301
@Test
293302
void shouldAllowParsingMultipleUseOfParameter() {
294303
String sql = "SELECT * FROM person where name = :id or lastname = :id";

0 commit comments

Comments
 (0)