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
7 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -677,7 +677,8 @@ entity_type_literal
677
677
678
678
escape_character
679
679
: CHARACTER
680
- | character_valued_input_parameter //
680
+ | string_literal
681
+ | character_valued_input_parameter
681
682
;
682
683
683
684
numeric_literal
Original file line number Diff line number Diff line change @@ -653,7 +653,8 @@ entity_type_literal
653
653
654
654
escape_character
655
655
: CHARACTER
656
- | character_valued_input_parameter //
656
+ | string_literal
657
+ | character_valued_input_parameter
657
658
;
658
659
659
660
numeric_literal
@@ -949,7 +950,7 @@ NOT_EQUAL : '<>' | '!=' ;
949
950
950
951
CHARACTER : ' \' ' (~ (' \' ' | ' \\ ' )) ' \' ' ;
951
952
IDENTIFICATION_VARIABLE : (' a' .. ' z' | ' A' .. ' Z' | ' \u0080 ' .. ' \ufffe ' | ' $' | ' _' ) (' a' .. ' z' | ' A' .. ' Z' | ' \u0080 ' .. ' \ufffe ' | ' 0' .. ' 9' | ' $' | ' _' )* ;
952
- STRINGLITERAL : ' \' ' (~ (' \' ' | ' \\ ' ))* ' \' ' ;
953
+ STRINGLITERAL : ' \' ' (~ (' \' ' | ' \\ ' )| ' \\ ' )* ' \' ' ;
953
954
JAVASTRINGLITERAL : ' "' ( (' \\ ' [btnfr" ']) | ~('" ' ))* ' " ';
954
955
FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
955
956
INTLITERAL : ('0' .. '9')+ ;
Original file line number Diff line number Diff line change @@ -2418,7 +2418,16 @@ public List<JpaQueryParsingToken> visitEntity_type_literal(EqlParser.Entity_type
2418
2418
2419
2419
@ Override
2420
2420
public List <JpaQueryParsingToken > visitEscape_character (EqlParser .Escape_characterContext ctx ) {
2421
- return List .of (new JpaQueryParsingToken (ctx .CHARACTER ()));
2421
+
2422
+ if (ctx .CHARACTER () != null ) {
2423
+ return List .of (new JpaQueryParsingToken (ctx .CHARACTER ()));
2424
+ } else if (ctx .character_valued_input_parameter () != null ) {
2425
+ return visit (ctx .character_valued_input_parameter ());
2426
+ } else if (ctx .string_literal () != null ) {
2427
+ return visit (ctx .string_literal ());
2428
+ }
2429
+
2430
+ return List .of ();
2422
2431
}
2423
2432
2424
2433
@ Override
Original file line number Diff line number Diff line change @@ -2225,7 +2225,16 @@ public List<JpaQueryParsingToken> visitEntity_type_literal(JpqlParser.Entity_typ
2225
2225
2226
2226
@ Override
2227
2227
public List <JpaQueryParsingToken > visitEscape_character (JpqlParser .Escape_characterContext ctx ) {
2228
- return List .of (new JpaQueryParsingToken (ctx .CHARACTER ()));
2228
+
2229
+ if (ctx .CHARACTER () != null ) {
2230
+ return List .of (new JpaQueryParsingToken (ctx .CHARACTER ()));
2231
+ } else if (ctx .character_valued_input_parameter () != null ) {
2232
+ return visit (ctx .character_valued_input_parameter ());
2233
+ } else if (ctx .string_literal () != null ) {
2234
+ return visit (ctx .string_literal ());
2235
+ }
2236
+
2237
+ return List .of ();
2229
2238
}
2230
2239
2231
2240
@ Override
Original file line number Diff line number Diff line change @@ -1038,6 +1038,14 @@ void signedExpressionsShouldWork(String query) {
1038
1038
assertQuery (query );
1039
1039
}
1040
1040
1041
+ @ Test // GH-3873
1042
+ void escapeClauseShouldWork () {
1043
+ assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
1044
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
1045
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
1046
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
1047
+ }
1048
+
1041
1049
@ ParameterizedTest // GH-3451
1042
1050
@ MethodSource ("reservedWords" )
1043
1051
void entityNameWithPackageContainingReservedWord (String reservedWord ) {
Original file line number Diff line number Diff line change @@ -1569,6 +1569,9 @@ void binaryLiteralsShouldWork() {
1569
1569
@ Test // GH-3040
1570
1570
void escapeClauseShouldWork () {
1571
1571
assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
1572
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
1573
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
1574
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
1572
1575
}
1573
1576
1574
1577
@ Test // GH-3062, GH-3056
Original file line number Diff line number Diff line change @@ -1046,6 +1046,14 @@ void signedExpressionsShouldWork(String query) {
1046
1046
assertQuery (query );
1047
1047
}
1048
1048
1049
+ @ Test // GH-3873
1050
+ void escapeClauseShouldWork () {
1051
+ assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
1052
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
1053
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
1054
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
1055
+ }
1056
+
1049
1057
@ ParameterizedTest // GH-3451
1050
1058
@ MethodSource ("reservedWords" )
1051
1059
void entityNameWithPackageContainingReservedWord (String reservedWord ) {
You can’t perform that action at this time.
0 commit comments