You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[JDBC-V2] Make DatabaseMetaDataImpl use PreparedStatement. #2739
bugjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)jdbc-metadataDetail: JDBC metadata (DatabaseMetaData, ResultSetMetaData, type mapping)queriesArea: how the client builds and runs statements (parameters, quoting, batches)
Recommendation: Close — already fixed #3171 binds the patterns of getSchemas, getPrimaryKeys and getFunctions as PreparedStatement parameters (first release v0.11.0). On main, the other metadata methods also bind or escape the values of the caller.
Status on main: Fixed on main — a pattern that leaves its literal returns no rows from any method, in both metadata modes; v0.10.0 returns rows from 3 methods.
Analysis: On main, the values of the caller go into the SQL as parameters (DatabaseMetaDataImpl.java:1069-1070, :1312-1313, :1871, :1927), or escaped with SQLUtils.enquoteLiteral (getColumns with jdbc_metadata_use_show_statements=false, DatabaseMetaDataImpl.java:1177-1179). The SHOW path binds the LIKE pattern and quotes the names (ShowStatementsMetaData.java:216, :339). The engine list at DatabaseMetaDataImpl.java:1023 comes from the driver, not from the caller.
Reproduction: complete program and output
importjava.sql.Connection;
importjava.sql.DatabaseMetaData;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.Statement;
importjava.util.Properties;
publicclassRepro {
staticfinalStringURL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
staticfinalStringPASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
// Matches nothing while it stays inside its literal, and everything when it leaves the literal.staticfinalStringP = "nomatch' OR '1'='1";
interfaceCall { ResultSetrun(DatabaseMetaDatamd) throwsException; }
staticStringcount(DatabaseMetaDatamd, Stringname, Callc) {
try (ResultSetrs = c.run(md)) {
intn = 0;
while (rs.next()) n++;
return" " + name + "=" + n;
} catch (Exceptione) {
return" " + name + "=" + e.getClass().getSimpleName() + ": " + e.getMessage();
}
}
publicstaticvoidmain(String[] args) throwsException {
Propertiesprops = newProperties();
props.setProperty("user", "default");
props.setProperty("password", PASSWORD);
Stringbase = "jdbc:clickhouse:" + URL.replaceFirst("^https?:", "") + "/default";
try (Connectionconn = DriverManager.getConnection(base, props); Statements = conn.createStatement()) {
s.execute("CREATE DATABASE IF NOT EXISTS triage2739");
s.execute("CREATE TABLE IF NOT EXISTS triage2739.t (id UInt32) ENGINE = MergeTree ORDER BY id");
}
for (Stringshow : newString[] {"true", "false"}) {
try (Connectionconn = DriverManager.getConnection(base + "?jdbc_metadata_use_show_statements=" + show, props)) {
DatabaseMetaDatamd = conn.getMetaData();
System.out.println("show_statements=" + show + ", rows:"
+ count(md, "getSchemas", m -> m.getSchemas(null, P))
+ count(md, "getTables(schema)", m -> m.getTables(null, P, "%", null))
+ count(md, "getTables(table)", m -> m.getTables(null, "triage2739", P, null))
+ count(md, "getColumns", m -> m.getColumns(null, "triage2739", "t", P))
+ count(md, "getPrimaryKeys", m -> m.getPrimaryKeys(null, P, "t"))
+ count(md, "getFunctions", m -> m.getFunctions(null, null, P))
+ count(md, "contrast getColumns(%)", m -> m.getColumns(null, "triage2739", "t", "%")));
}
}
try (Connectionconn = DriverManager.getConnection(base, props); Statements = conn.createStatement()) {
s.execute("DROP DATABASE IF EXISTS triage2739");
}
}
}
Output on v0.10.0 (Maven Central), ClickHouse 26.11.2.4. v0.10.0 does not have jdbc_metadata_use_show_statements, so the loop runs once without it, with compress=0 (#3107):
bugjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)jdbc-metadataDetail: JDBC metadata (DatabaseMetaData, ResultSetMetaData, type mapping)queriesArea: how the client builds and runs statements (parameters, quoting, batches)
Activity
polyglotAI-bot commentedon Nov 28, 2026
Recommendation: Close — already fixed
#3171 binds the patterns of
getSchemas,getPrimaryKeysandgetFunctionsasPreparedStatementparameters (first release v0.11.0). Onmain, the other metadata methods also bind or escape the values of the caller.main: Fixed on main — a pattern that leaves its literal returns no rows from any method, in both metadata modes; v0.10.0 returns rows from 3 methods.Analysis: On
main, the values of the caller go into the SQL as parameters (DatabaseMetaDataImpl.java:1069-1070,:1312-1313,:1871,:1927), or escaped withSQLUtils.enquoteLiteral(getColumnswithjdbc_metadata_use_show_statements=false,DatabaseMetaDataImpl.java:1177-1179). The SHOW path binds theLIKEpattern and quotes the names (ShowStatementsMetaData.java:216,:339). The engine list atDatabaseMetaDataImpl.java:1023comes from the driver, not from the caller.Reproduction: complete program and output
Output on
main(8480ca001), ClickHouse 26.11.2.4:Output on v0.10.0 (Maven Central), ClickHouse 26.11.2.4. v0.10.0 does not have
jdbc_metadata_use_show_statements, so the loop runs once without it, withcompress=0(#3107):Automated triage by Polyglot AI. A maintainer makes the final decision.