File tree Expand file tree Collapse file tree 7 files changed +44
-5
lines changed
antlr4/org/springframework/data/jpa/repository/query
java/org/springframework/data/jpa/repository/query
test/java/org/springframework/data/jpa/repository/query Expand file tree Collapse file tree 7 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -688,7 +688,8 @@ entity_type_literal
688688
689689escape_character
690690 : CHARACTER
691- | character_valued_input_parameter //
691+ | string_literal
692+ | character_valued_input_parameter
692693 ;
693694
694695numeric_literal
Original file line number Diff line number Diff line change @@ -674,7 +674,8 @@ entity_type_literal
674674
675675escape_character
676676 : CHARACTER
677- | character_valued_input_parameter //
677+ | string_literal
678+ | character_valued_input_parameter
678679 ;
679680
680681numeric_literal
@@ -982,7 +983,7 @@ NOT_EQUAL : '<>' | '!=' ;
982983
983984CHARACTER : ' \' ' (~ (' \' ' | ' \\ ' )) ' \' ' ;
984985IDENTIFICATION_VARIABLE : (' a' .. ' z' | ' A' .. ' Z' | ' \u0080 ' .. ' \ufffe ' | ' $' | ' _' ) (' a' .. ' z' | ' A' .. ' Z' | ' \u0080 ' .. ' \ufffe ' | ' 0' .. ' 9' | ' $' | ' _' )* ;
985- STRINGLITERAL : ' \' ' (~ (' \' ' | ' \\ ' ))* ' \' ' ;
986+ STRINGLITERAL : ' \' ' (~ (' \' ' | ' \\ ' )| ' \\ ' )* ' \' ' ;
986987JAVASTRINGLITERAL : ' "' ( (' \\ ' [btnfr" ']) | ~('" ' ))* ' " ';
987988FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
988989INTLITERAL : ('0' .. '9')+ ;
Original file line number Diff line number Diff line change @@ -2309,7 +2309,16 @@ public QueryTokenStream visitEntity_type_literal(EqlParser.Entity_type_literalCo
23092309
23102310 @ Override
23112311 public QueryTokenStream visitEscape_character (EqlParser .Escape_characterContext ctx ) {
2312- return QueryRendererBuilder .from (QueryTokens .token (ctx .CHARACTER ()));
2312+
2313+ if (ctx .CHARACTER () != null ) {
2314+ return QueryRendererBuilder .from (QueryTokens .token (ctx .CHARACTER ()));
2315+ } else if (ctx .character_valued_input_parameter () != null ) {
2316+ return visit (ctx .character_valued_input_parameter ());
2317+ } else if (ctx .string_literal () != null ) {
2318+ return visit (ctx .string_literal ());
2319+ }
2320+
2321+ return QueryTokenStream .empty ();
23132322 }
23142323
23152324 @ Override
Original file line number Diff line number Diff line change @@ -2182,7 +2182,16 @@ public QueryTokenStream visitEntity_type_literal(JpqlParser.Entity_type_literalC
21822182
21832183 @ Override
21842184 public QueryTokenStream visitEscape_character (JpqlParser .Escape_characterContext ctx ) {
2185- return QueryRenderer .from (QueryTokens .expression (ctx .CHARACTER ()));
2185+
2186+ if (ctx .CHARACTER () != null ) {
2187+ return QueryRenderer .from (QueryTokens .expression (ctx .CHARACTER ()));
2188+ } else if (ctx .character_valued_input_parameter () != null ) {
2189+ return visit (ctx .character_valued_input_parameter ());
2190+ } else if (ctx .string_literal () != null ) {
2191+ return visit (ctx .string_literal ());
2192+ }
2193+
2194+ return QueryTokenStream .empty ();
21862195 }
21872196
21882197 @ Override
Original file line number Diff line number Diff line change @@ -1056,6 +1056,14 @@ void signedExpressionsShouldWork(String query) {
10561056 assertQuery (query );
10571057 }
10581058
1059+ @ Test // GH-3873
1060+ void escapeClauseShouldWork () {
1061+ assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
1062+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
1063+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
1064+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
1065+ }
1066+
10591067 @ ParameterizedTest // GH-3451
10601068 @ MethodSource ("reservedWords" )
10611069 void entityNameWithPackageContainingReservedWord (String reservedWord ) {
Original file line number Diff line number Diff line change @@ -1801,6 +1801,9 @@ void binaryLiteralsShouldWork() {
18011801 @ Test // GH-3040
18021802 void escapeClauseShouldWork () {
18031803 assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
1804+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
1805+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
1806+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
18041807 }
18051808
18061809 @ Test // GH-3062, GH-3056
Original file line number Diff line number Diff line change @@ -1049,6 +1049,14 @@ void signedExpressionsShouldWork(String query) {
10491049 assertQuery (query );
10501050 }
10511051
1052+ @ Test // GH-3873
1053+ void escapeClauseShouldWork () {
1054+ assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
1055+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
1056+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
1057+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
1058+ }
1059+
10521060 @ ParameterizedTest // GH-3451
10531061 @ MethodSource ("reservedWords" )
10541062 void entityNameWithPackageContainingReservedWord (String reservedWord ) {
You can’t perform that action at this time.
0 commit comments