ClickHouse / ClickHouse/clickhouse-java

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

Abierto
#2,835 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
1.6k
Forks
636
Merge medio
2 d 23 h
PR fusionados (30 d)
29

Descripción

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java, sql
Área
database
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
58/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.