File tree Expand file tree Collapse file tree 7 files changed +43
-7
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 +43
-7
lines changed Original file line number Diff line number Diff line change @@ -709,7 +709,8 @@ entity_type_literal
709
709
710
710
escape_character
711
711
: CHARACTER
712
- | character_valued_input_parameter //
712
+ | string_literal
713
+ | character_valued_input_parameter
713
714
;
714
715
715
716
numeric_literal
Original file line number Diff line number Diff line change @@ -695,7 +695,8 @@ entity_type_literal
695
695
696
696
escape_character
697
697
: CHARACTER
698
- | character_valued_input_parameter //
698
+ | string_literal
699
+ | character_valued_input_parameter
699
700
;
700
701
701
702
numeric_literal
Original file line number Diff line number Diff line change @@ -2336,7 +2336,16 @@ public QueryTokenStream visitEntity_type_literal(EqlParser.Entity_type_literalCo
2336
2336
2337
2337
@ Override
2338
2338
public QueryTokenStream visitEscape_character (EqlParser .Escape_characterContext ctx ) {
2339
- return QueryTokenStream .ofToken (ctx .CHARACTER ());
2339
+
2340
+ if (ctx .CHARACTER () != null ) {
2341
+ return QueryTokenStream .ofToken (ctx .CHARACTER ());
2342
+ } else if (ctx .character_valued_input_parameter () != null ) {
2343
+ return visit (ctx .character_valued_input_parameter ());
2344
+ } else if (ctx .string_literal () != null ) {
2345
+ return visit (ctx .string_literal ());
2346
+ }
2347
+
2348
+ return QueryTokenStream .empty ();
2340
2349
}
2341
2350
2342
2351
@ Override
Original file line number Diff line number Diff line change @@ -2298,7 +2298,16 @@ public QueryTokenStream visitEntity_type_literal(JpqlParser.Entity_type_literalC
2298
2298
2299
2299
@ Override
2300
2300
public QueryTokenStream visitEscape_character (JpqlParser .Escape_characterContext ctx ) {
2301
- return QueryTokenStream .ofToken (ctx .CHARACTER ());
2301
+
2302
+ if (ctx .CHARACTER () != null ) {
2303
+ return QueryTokenStream .ofToken (ctx .CHARACTER ());
2304
+ } else if (ctx .character_valued_input_parameter () != null ) {
2305
+ return visit (ctx .character_valued_input_parameter ());
2306
+ } else if (ctx .string_literal () != null ) {
2307
+ return visit (ctx .string_literal ());
2308
+ }
2309
+
2310
+ return QueryTokenStream .empty ();
2302
2311
}
2303
2312
2304
2313
@ Override
Original file line number Diff line number Diff line change @@ -1136,6 +1136,14 @@ void signedExpressionsShouldWork(String query) {
1136
1136
assertQuery (query );
1137
1137
}
1138
1138
1139
+ @ Test // GH-3873
1140
+ void escapeClauseShouldWork () {
1141
+ assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
1142
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
1143
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
1144
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
1145
+ }
1146
+
1139
1147
@ ParameterizedTest // GH-3451
1140
1148
@ MethodSource ("reservedWords" )
1141
1149
void entityNameWithPackageContainingReservedWord (String reservedWord ) {
Original file line number Diff line number Diff line change 19
19
20
20
import java .util .stream .Stream ;
21
21
22
- import org .antlr .v4 .runtime .CharStreams ;
23
- import org .antlr .v4 .runtime .CommonTokenStream ;
24
- import org .junit .jupiter .api .Disabled ;
25
22
import org .junit .jupiter .api .Test ;
26
23
import org .junit .jupiter .params .ParameterizedTest ;
27
24
import org .junit .jupiter .params .provider .Arguments ;
@@ -2170,6 +2167,9 @@ void binaryLiteralsShouldWork() {
2170
2167
@ Test // GH-3040
2171
2168
void escapeClauseShouldWork () {
2172
2169
assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
2170
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
2171
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
2172
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
2173
2173
}
2174
2174
2175
2175
@ Test // GH-3062, GH-3056
Original file line number Diff line number Diff line change @@ -1394,6 +1394,14 @@ void signedExpressionsShouldWork(String query) {
1394
1394
assertQuery (query );
1395
1395
}
1396
1396
1397
+ @ Test // GH-3873
1398
+ void escapeClauseShouldWork () {
1399
+ assertQuery ("select t.name from SomeDbo t where t.name LIKE :name escape '\\ \\ '" );
1400
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE '\\ \\ '" );
1401
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE ?1" );
1402
+ assertQuery ("SELECT e FROM SampleEntity e WHERE LOWER(e.label) LIKE LOWER(?1) ESCAPE :param" );
1403
+ }
1404
+
1397
1405
@ ParameterizedTest // GH-3451
1398
1406
@ MethodSource ("reservedWords" )
1399
1407
void entityNameWithPackageContainingReservedWord (String reservedWord ) {
You can’t perform that action at this time.
0 commit comments