Skip to content

invalid parameter count with CTEs in 0.92 #2595

@dpsutton

Description

@dpsutton

Likely should be included in #2576

jdbc-v2 0.9.2

Description

Running queries with CTEs and parameters results in errors because the PreparedStatement thinks it has 0 parameters

Steps to reproduce

Working in 0.8.4:

❯ clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.8.4"}}}' -J"$(socket-repl 6084)"
user=> (defn query-info [sql]
         ;; parse param names and replace {{id}} with ?
         (with-open [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123" "default" "password")
                     stmt (.prepareStatement conn sql)]
           (.. stmt getParameterMetaData getParameterCount)))
#'user/query-info
user=> (query-info "SELECT `source`.`id` AS `id`,
                      `source`.`val` AS `val` FROM
               (with base as (\n select 1 id, 'abc' val\n)\nselect * from base)
               AS `source`
               WHERE `positionCaseInsensitiveUTF8`(`source`.`val`, ?) > ? LIMIT 2000")
2

Broken in 0.9.2:

❯ clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.9.2"}}}' -J"$(socket-repl 6092)"
user=> (defn query-info [sql]
         ;; parse param names and replace {{id}} with ?
         (with-open [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123" "default" "password")
                     stmt (.prepareStatement conn sql)]
           (.. stmt getParameterMetaData getParameterCount)))
#'user/query-info
user=> (query-info "SELECT `source`.`id` AS `id`,
                      `source`.`val` AS `val` FROM
               (with base as (\n select 1 id, 'abc' val\n)\nselect * from base)
               AS `source`
               WHERE `positionCaseInsensitiveUTF8`(`source`.`val`, ?) > ? LIMIT 2000")
0

Expected Behaviour

The 0.9.2 driver should recognize the positionCaseInsensitiveUTF8(val, ?) > ? expression after the CTE. This is the way that we do a "string includes" operation.

Code Example

shown above in repro

Environment

  • Cloud
  • Client version:
  • Language version:
  • OS:

ClickHouse Server

just running clickhouse server latest in docker

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions