rxjava2-jdbc icon indicating copy to clipboard operation
rxjava2-jdbc copied to clipboard

Same NamedParameters used multiple times

Open Mu4h4h4 opened this issue 7 years ago • 2 comments

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

Mu4h4h4 avatar Jan 27 '18 02:01 Mu4h4h4

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||',' ...

davidmoten avatar Jan 27 '18 19:01 davidmoten

@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

KMax avatar Apr 24 '19 13:04 KMax