Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support escaping variable names #423

Closed
augustobmoura opened this issue Mar 2, 2020 · 2 comments · Fixed by #778
Closed

Support escaping variable names #423

augustobmoura opened this issue Mar 2, 2020 · 2 comments · Fixed by #778
Labels
status: pr submitted A pull request has been submitted for the issue type: improvement A minor improvement to an existing feature

Comments

@augustobmoura
Copy link

augustobmoura commented Mar 2, 2020

Steps to Reproduce

  1. Configure a project with micronaut and micronaut data
  2. Create a Postgres database
    3 Try to use a native query with cast using double colon:
@Repository
interface FooRepository {
  @Query(value "SELECT '1'::INTEGER", nativeQuery = true)
  Integer findConstant();
}

Shoul throw a error because INTEGER is not a declared parameter (all fine until here)
4. Try to escape the colons to force them to not be understood as a parameter

@Repository
interface FooRepository {
  @Query(value "SELECT '1'\\:\\:INTEGER", nativeQuery = true)
  Integer findConstant();
}

Expected Behaviour

To be possible to escape colons in native queries

Actual Behaviour

It still throws a error at compile time telling that INTEGER is not a declared parameter

Environment Information

  • Operating System: Ubuntu 18.04
  • Micronaut Version: 1.3.0/ Data: 1.0.0
  • JDK Version: Adopt11+OpenJ9

Edit:
I'm solving this problem at the moment by using the other syntax for casting in postgres https://www.postgresql.org/docs/current/typeconv-func.html

@augustobmoura
Copy link
Author

I tracked the bug to lines:

Pattern VARIABLE_PATTERN = Pattern.compile("(:([a-zA-Z0-9]+))");

and:
Matcher matcher = QueryBuilder.VARIABLE_PATTERN.matcher(queryString);

@graemerocher graemerocher added the type: improvement A minor improvement to an existing feature label Mar 17, 2020
@graemerocher graemerocher changed the title Repository native queries colon escaping Support escaping variable names Mar 17, 2020
@stale
Copy link

stale bot commented May 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pr submitted A pull request has been submitted for the issue type: improvement A minor improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants