You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi and thanks for JDBI,
I've noticed that bindList doesn't work correctly if the name of a list named parameters contains a dot, e.g. <like.this>, it seems that when building the query the parameter list is not being replaced in the query in this case. Normal named parameters with a dot work without any issues.
For example, this snippet works:
Jdbi jdbi = Jdbi.create("jdbc:h2:mem:test;Mode=Oracle;DB_CLOSE_DELAY=-1"); // (H2 in-memory database)
jdbi.setSqlLogger(new Slf4JSqlLogger());
List<String> names = jdbi.withHandle(handle -> {
handle.execute("CREATE TABLE \"user\" (id INTEGER PRIMARY KEY, name_id VARCHAR)");
handle.createUpdate("INSERT INTO \"user\" (id, name_id) VALUES (?, ?)")
.bind(0, 1) // 0-based parameter indexes
.bind(1, "Bob")
.execute();
handle.createUpdate("INSERT INTO \"user\" (id, name_id) VALUES (:id, :name)")
.bind("id", 2)
.bind("name", "Clarice")
.execute();
List<String> res = handle.createQuery("SELECT name_id FROM \"user\" WHERE ((id >:dot.id) AND name_id IN (<names>) AND id >:dot.id)")
.bindList("names",List.of("1","2","Bob","Clarice"))
.bind("dot.id",-1)
.mapTo(String.class)
.list();
But when I rename names to nam.es:
List<String> res = handle.createQuery("SELECT name_id FROM \"user\" WHERE ((id >:dot.id) AND name_id IN (<nam.es>) AND id >:dot.id)")
.bindList("nam.es",List.of("1","2","Bob","Clarice"))
.bind("dot.id",-1)
.mapTo(String.class)
.list();
The example above fails with an exception (generic H2 exception):
org.jdbi.v3.core.statement.UnableToCreateStatementException: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT name_id FROM ""user"" WHERE ((id >?) AND name_id IN ([*]<nam.es>) AND id >?)"; expected "INTERSECTS (, NOT, EXISTS, UNIQUE, INTERSECTS"; SQL statement:
SELECT name_id FROM "user" WHERE ((id >?) AND name_id IN (<nam.es>) AND id >?) [42001-220] [statement:"SELECT name_id FROM "user" WHERE ((id >:dot.id) AND name_id IN (<nam.es>) AND id >:dot.id)", arguments:{positional:{}, named:{dot.id:-1,__nam.es_1:2,__nam.es_2:Bob,__nam.es_3:Clarice,__nam.es_0:1}, finder:[]}]
at org.jdbi.v3.core.statement.SqlStatement.internalExecute(SqlStatement.java:1789)
at org.jdbi.v3.core.result.ResultProducers.lambda$createResultBearing$3(ResultProducers.java:94)
at org.jdbi.v3.core.result.internal.ResultSetResultIterable.iterator(ResultSetResultIterable.java:51)
at org.jdbi.v3.core.result.ResultIterable.stream(ResultIterable.java:266)
at org.jdbi.v3.core.result.ResultIterable.collect(ResultIterable.java:340)
I would expect to see something like AND name_id IN (__nam.es_0,__nam.es_1, __nam.es_2,__nam.es_3) but it seems that the replacement is not taking place.
Luckily, just not using dots for those aliases works as a workaround.
The text was updated successfully, but these errors were encountered:
This is a lexer limitation. Technically not a bug but just a limitation. I will add a fix that will allow the . to be a valid character in the default ("DefinedAttributeTemplateEngine") template engine.
Hi and thanks for JDBI,
I've noticed that bindList doesn't work correctly if the name of a list named parameters contains a dot, e.g. <like.this>, it seems that when building the query the parameter list is not being replaced in the query in this case. Normal named parameters with a dot work without any issues.
For example, this snippet works:
But when I rename
names
tonam.es
:The example above fails with an exception (generic H2 exception):
I would expect to see something like
AND name_id IN (__nam.es_0,__nam.es_1, __nam.es_2,__nam.es_3)
but it seems that the replacement is not taking place.Luckily, just not using dots for those aliases works as a workaround.
The text was updated successfully, but these errors were encountered: