SQL parameter parsing strategy - why must parameters be valid java identifiers?

Skip to first unread message


Apr 19, 2017, 8:40:32 AM4/19/17
to sql2o

We're using another library as a query builder (JOOQ) along with sql2o and we've found ourselves in a very unpleasant situation. The query builder library that we use generates numeric names for parameters, which cannot be parsed by sql2o, because they are not valid java identifiers.
Example query (MySQL):
 UPDATE table t SET t.columnA = :1, t.columnB = :2

And this is the exception thrown when executing the query:
org.sql2o.Sql2oException: Failed to add parameter with name '1'. No parameter with that name is declared in the sql.
at org.sql2o.Query.addParameterInternal(Query.java:138) ~[sql2o-1.6.0-RC2.jar:?]
at org.sql2o.Query.addParameter(Query.java:259) ~[sql2o-1.6.0-RC2.jar:?]
at org.sql2o.Query.addParameter(Query.java:165) ~[sql2o-1.6.0-RC2.jar:?]
at org.sql2o.Query.addParameter(Query.java:203) ~[sql2o-1.6.0-RC2.jar:?]

So what is the specific reason that sql2o needs param names to be valid java identifiers? Could we safely write ourselves a workaround that allows names like :1, :2 etc.? What would be another possible solution?

BTW: We've tried making the query builder spit out named parameters, but that did not work out.
Thanks in advance.

Reply all
Reply to author
0 new messages