ClickHouse / ClickHouse/clickhouse-java
JDBC Driver: PreparedStatement counts ? placeholders inside SQL comments (regression since 0.1.36)
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 636
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 28
Description
## Problem
When a SQL query contains parameters inside comments (e.g. `-- filter by ${param}`
which gets replaced with `-- filter by ?` before reaching the driver), the driver
counts those `?` placeholders inside comments as actual parameters.
This causes:
- Old driver (ru.yandex, 0.1.x): `ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2`
- New driver (com.clickhouse, 0.3+): `Parameter index must between 1 and 2 but we got 3`
## Example SQL (after parameter substitution by the application)
```sql
-- filter by ? and ?
SELECT *
FROM my_table
WHERE severity = ?
AND status = ?
```
Driver sees 4 placeholders, application binds 2 values → exception.
## Expected behavior
`?` inside SQL comments (`--` and `/* */`) should be ignored when counting
PreparedStatement parameter placeholders.
## Versions tested
All versions below have this bug:
- 0.2.6
- 0.3.2
- 0.4.6
- 0.5.0
- 0.7.2 (with both `com.clickhouse.jdbc.ClickHouseDriver` and `ru.yandex.clickhouse.ClickHouseDriver`)
- 0.9.8 (with `ClickHouseDriver`, `DriverV1`, and `jdbc_sql_parser=JAVACC/ANTLR4/ANTLR4_PARAMS_PARSER`)
## Working version
`clickhouse-jdbc-0.1.36` (ru.yandex.clickhouse.ClickHouseDriver) correctly ignores
`?` inside comments.
## Environment
- ClickHouse server: 25.3 / 25.8
- Pentaho 9.4 (CDA/PRE data access)
- Java 11
Contributor guide
Assessment
This issue has not been assessed yet.