Skip to content

Commit

Permalink
Merge pull request #444 from eclipse/ISSUE-441
Browse files Browse the repository at this point in the history
query specification doesnt allow for dashes in tablenames
  • Loading branch information
otaviojava authored Sep 25, 2023
2 parents 6a6bb57 + 1772223 commit ae7ed61
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
- Remove exception at the delete methods at the repositories proxies
- Add support to LIKE conditions parameterized at Repository methods annotated with `@Query`
- Enhance the error message when the entity in the repository does not have the Entity annotation
- query specification doesnt allow for dashes in table names

== [1.0.1] - 2023-7-31

Expand Down
5 changes: 3 additions & 2 deletions antlr4/org/eclipse/jnosql/query/grammar/Query.g4
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
grammar Query;

select: 'select' fields 'from' entity where? skip? limit? order? EOF;
delete: 'delete' deleteFields? 'from' entity where? EOF;
insert: 'insert' entity (conditions | json) ttl? EOF;
Expand Down Expand Up @@ -55,8 +56,8 @@ parameter: PARAMETER;
STRING : '\'' ( ESC | ~('\\'|'\'') )* '\'' |'"' ( ESC | ~('\\'|'"') )* '"';
INT: [0-9]+;
NUMBER: INT [.]? INT?;
ANY_NAME: [a-zA-Z_.] [a-zA-Z._0-9]*;
PARAMETER:'@'[a-zA-Z._0-9]*;
ANY_NAME: [a-zA-Z_.][a-zA-Z_.0-9-]*;
PARAMETER: '@' ANY_NAME;
WS: [ \t\r\n]+ -> skip ;
SL_COMMENT: '//' .*? '\n' -> skip;
fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
Expand Down
2 changes: 1 addition & 1 deletion antlr4/org/eclipse/jnosql/query/grammar/method/Method.g4
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ in: variable not? 'In';
like: variable not? 'Like';
not: 'Not';
variable: ANY_NAME;
ANY_NAME: [a-zA-Z_.] [a-zA-Z._0-9]*;
ANY_NAME: [a-zA-Z_.][a-zA-Z_.0-9-]*;
WS: [ \t\r\n]+ -> skip ;
fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
fragment UNICODE : 'u' HEX HEX HEX HEX ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,28 @@ public void shouldReturnParserQuery29(String query) {
assertEquals(LocalDate.class, params[1]);
}

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = {"select * from my-prefix-user where user_id = 123"})
public void shouldReturnParserQuery30(String query) {
DefaultSelectQuery selectQuery = selectQueryConverter.apply(query);

assertEquals("my-prefix-user", selectQuery.entity());
assertTrue(selectQuery.fields().isEmpty());
assertTrue(selectQuery.orderBy().isEmpty());
assertEquals(0, selectQuery.limit());
assertEquals(0, selectQuery.skip());
assertTrue(selectQuery.where().isPresent());

Where where = selectQuery.where().get();
QueryCondition condition = where.condition();
QueryValue<?> value = condition.value();
Assertions.assertEquals(Condition.EQUALS, condition.condition());
assertEquals("user_id", condition.name());
assertTrue(value instanceof NumberQueryValue);
Number result = NumberQueryValue.class.cast(value).get();
assertThat(result).isEqualTo(123L);
}



private DefaultSelectQuery checkSelectFromStart(String query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ delete from Person where not age <= @age
delete from Person where not age between @age1 and @age
delete from Person where not age between @age1 and 10 and salary = convert(10,java.lang.Integer)
#json
delete from Person where siblings = {"apollo": "brother", "zeus": "father"}
delete from Person where siblings = {"apollo": "brother", "zeus": "father"}
#dashes
delete from my-prefix-user where not user-id <= @user_id
delete from my_prefix_user where not user_id <= @user_id
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ insert Person {"name":"Ada Lovelace"} 10 hour
insert Person {"name":"Ada Lovelace"} 10 minute
insert Person {"name":"Ada Lovelace"} 10 second
insert Person {"name":"Ada Lovelace"} 10 millisecond
insert Person {"name":"Ada Lovelace"} 10 nanosecond
insert Person {"name":"Ada Lovelace"} 10 nanosecond
#dashes
insert my-prefix-user (user-id = @user-id)
insert my_prefix_user (user-id = @user_id)
insert my-prefix-user-1 (user-id-1 = @user-id)
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ select * from Person where not age <= @age
select * from Person where not age between @age1 and @age
select * from Person where not age between @age1 and 10 and salary = convert(10,java.lang.Integer)
#json
select * from Person where siblings = {"apollo": "brother", "zeus": "father"}
select * from Person where siblings = {"apollo": "brother", "zeus": "father"}
#dashes
select * from my-prefix-user where user-id = 123
select * from my_prefix_user where user_id = 123

0 comments on commit ae7ed61

Please sign in to comment.