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

Same NamedParameters used multiple times #19

Open
Mu4h4h4 opened this issue Jan 27, 2018 · 2 comments
Open

Same NamedParameters used multiple times #19

Mu4h4h4 opened this issue Jan 27, 2018 · 2 comments
Labels

Comments

@Mu4h4h4
Copy link
Contributor

Mu4h4h4 commented Jan 27, 2018

MySQL

String query = "SELECT * FROM table
WHERE ST_CONTAINS(GEOMFROMTEXT('POLYGON((:neLon :neLat, :neLon :swLat, :swLon :swLat, :swLon :neLat,:neLon :neLat))'), point)"
return database
                    .select(query)
                    .parameter("swLon", swLon)
                    .parameter("swLat", swLat)
                    .parameter("neLon", neLon)
                    .parameter("neLat", neLat)
                    .get(new Mapper())

This won't work but when I hardcode the lat's and lng's it works fine. Are we not allowed to use named parameters in multiple places and assign value only once?

Thank you very much for all your help!

Kind Regards,
Vini

@davidmoten
Copy link
Owner

Repeated use of named parameters is allowed. The problem you have is no parameter substitution will occur in the middle of a quoted string. You would have to do something like this:

`POLYGON((`||:neLon||` `||:neLat||',' ...

@KMax
Copy link

KMax commented Apr 24, 2019

@davidmoten Does it actually work? I have two parameters and each of them is used twice in the query. But still I got the following exception:

java.lang.IllegalArgumentException: number of values should be a multiple of number of parameters in sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants