ClickHouse / ClickHouse/clickhouse-java

JDBC Driver: PreparedStatement counts ? placeholders inside SQL comments (regression since 0.1.36)

未关闭
#2,835 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Java
星标
1.6k
派生
636
平均合并
2 天 23 小时
30 天内合并 PR
29

描述

## 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

贡献指南

打开贡献指南

调研方向

首先跟踪 ClickHouseDriver 和 DriverV1 的参数计数,并比较报告中提到的 jdbc_sql_parser 模式。使用 -- 和 /* */ 注释分别重现该查询,然后添加覆盖测试,表明只有注释之外的占位符可以绑定,并验证报告的参数索引错误已经消失。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, sql
领域
database
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
58/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。