ClickHouse / ClickHouse/clickhouse-java

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

Ouverte
#2,835 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Java
Étoiles
1.6k
Forks
636
Merge moyen
2 j 23 h
PR mergées (30 j)
29

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

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Start by tracing parameter counting from ClickHouseDriver and DriverV1, comparing the jdbc_sql_parser modes named in the report. Reproduce the query with both -- and /* */ comments, then add coverage showing that only placeholders outside comments are bindable and verify the reported parameter-index errors are gone.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java, sql
Domaine
database
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
58/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.