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
This commit is contained in:
parent
d86af57e0f
commit
bc2895a30b
|
@ -56,12 +56,12 @@ abstract class NamedParameterUtils {
|
||||||
/**
|
/**
|
||||||
* Set of characters that qualify as comment or quote starting characters.
|
* 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.
|
* 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,
|
* Set of characters that qualify as parameter separators,
|
||||||
|
|
|
@ -251,6 +251,7 @@ class NamedParameterUtilsTests {
|
||||||
"SELECT /*:doo*/':foo', :xxx FROM DUAL",
|
"SELECT /*:doo*/':foo', :xxx FROM DUAL",
|
||||||
"SELECT ':foo'/*:doo*/, :xxx FROM DUAL",
|
"SELECT ':foo'/*:doo*/, :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) {
|
void parseSqlStatementWithParametersInsideQuotesAndComments(String sql) {
|
||||||
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||||
|
@ -289,6 +290,14 @@ class NamedParameterUtilsTests {
|
||||||
assertThat(psql.getParameterNames()).containsExactly("headers[id]");
|
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
|
@Test
|
||||||
void shouldAllowParsingMultipleUseOfParameter() {
|
void shouldAllowParsingMultipleUseOfParameter() {
|
||||||
String sql = "SELECT * FROM person where name = :id or lastname = :id";
|
String sql = "SELECT * FROM person where name = :id or lastname = :id";
|
||||||
|
|
Loading…
Reference in New Issue