Skip to content

[jdbc-v2] PreparedStatementImpl parses SQL incorectly #2354

@aira-xite

Description

@aira-xite

When trying to insert multiple lines using SQL

insert into apollo.tmp_jdbc_test (name, age) values (?, ?)

execution fails with the following exception:

DB::Exception: Syntax error: failed at position 1 (inser): inser t into apollo.tmp_jdbc_test (name, age) values ('insertMany1', 333),t into apollo.tmp_jdbc_test (name, age) values ('insertMany2', NULL);. 

After some digging I found that the failure occurs because com.clickhouse.jdbc.PreparedStatementImpl#PreparedStatementImpl parses the input SQL into segments incorrectly. It assumes the input String sql is entirely upper-case, which produces an invalid result. Specifically, this line

this.insertIntoSQL = this.originalSql.substring(0, this.originalSql.indexOf("VALUES") + 6);

looks for "VALUES" in the input string. When the keyword is lowercase, indexOf("VALUES") returns -1; adding 6 yields 5, so this.insertIntoSQL becomes "inser".

I can open a PR to fix this particular case by upper-casing originalSql before calling indexOf, but there might be other similar errors in the repository that are also worth checking.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions