micronaut-data icon indicating copy to clipboard operation
micronaut-data copied to clipboard

`@Query` doesn't escape reserved keywords

Open melix opened this issue 1 year ago • 3 comments

Expected Behavior

If a method is annotated with @Query, I would expect the query to escape reserved keywords. For example:

@Query("update user set locked=true where id=:id")
void lock(Long id);

user is a reserved name in PostgreSQL.

Actual Behaviour

The user table is not escaped. Even if you use the following query:

@Query("update \"user\" set locked=true where id=:id")
void lock(Long id);

The converted query removes escaping.

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

4.6.2

melix avatar Apr 09 '24 13:04 melix

@dstepanov @radovanradic maybe we could create a dictionary of reserved words per dialect

sdelamo avatar Apr 19 '24 05:04 sdelamo

We don't want to parse queries more than we do now (just to replace binding). If you use a custom query, you should be doing escaping; I'm not sure why, in this case, the escaping disappears.

dstepanov avatar Apr 19 '24 10:04 dstepanov

@melix I cannot reproduce your issue https://github.com/micronaut-projects/micronaut-data/pull/2900

dstepanov avatar Apr 22 '24 12:04 dstepanov

Closing it because I cannot reproduce it

dstepanov avatar Sep 09 '24 09:09 dstepanov