Skip to content

Commit

Permalink
Support backticks for quoted identifiers in spring-r2dbc
Browse files Browse the repository at this point in the history
NamedParameterUtils in spring-r2dbc now supports MySQL-style backticks
for quoted identifiers for consistency with spring-jdbc.

See gh-31944
Closes gh-32285
  • Loading branch information
sbrannen committed Feb 17, 2024
1 parent d86af57 commit bc2895a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ abstract class NamedParameterUtils {
/**
* Set of characters that qualify as comment or quote starting characters.
*/
private static final String[] START_SKIP = {"'", "\"", "--", "/*"};
private static final String[] START_SKIP = {"'", "\"", "--", "/*", "`"};

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

/**
* Set of characters that qualify as parameter separators,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ void variableAssignmentOperator() {
"SELECT /*:doo*/':foo', :xxx FROM DUAL",
"SELECT ':foo'/*:doo*/, :xxx FROM DUAL",
"SELECT \":foo\"\":doo\", :xxx FROM DUAL",
"SELECT `:foo``:doo`, :xxx FROM DUAL"
})
void parseSqlStatementWithParametersInsideQuotesAndComments(String sql) {
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
Expand Down Expand Up @@ -289,6 +290,14 @@ void namedParamMapReference() {
assertThat(psql.getParameterNames()).containsExactly("headers[id]");
}

@Test // gh-31944 / gh-32285
void parseSqlStatementWithBackticks() {
String sql = "select * from `tb&user` where id = :id";
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
assertThat(parsedSql.getParameterNames()).containsExactly("id");
assertThat(expand(parsedSql)).isEqualTo("select * from `tb&user` where id = $1");
}

@Test
void shouldAllowParsingMultipleUseOfParameter() {
String sql = "SELECT * FROM person where name = :id or lastname = :id";
Expand Down

0 comments on commit bc2895a

Please sign in to comment.