diff --git a/client-v2/src/main/java/com/clickhouse/client/api/Client.java b/client-v2/src/main/java/com/clickhouse/client/api/Client.java index da6ab010b..621f88efb 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/Client.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/Client.java @@ -2290,6 +2290,9 @@ record = allocator == null ? clazz.getDeclaredConstructor().newInstance() : allo /** *

Fetches schema of a table and returns complete information about each column. * Information includes column name, type, default value, etc.

+ *

Important: table name should be properly escaped + * (see @link com.clickhouse.client.api.sql.SQLUtils#enquoteIdentifier(java.lang.String, boolean)). + * This method uses table name as is because method is not aware if database name also present and cannot properly escape it.

* *

See {@link #register(Class, TableSchema)}

* @@ -2304,6 +2307,9 @@ public TableSchema getTableSchema(String table) { *

Fetches schema of a table and returns complete information about each column. * Information includes column name, type, default value, etc.

*

See {@link #register(Class, TableSchema)}

+ *

Important: table name should be properly escaped + * (see @link com.clickhouse.client.api.sql.SQLUtils#enquoteIdentifier(java.lang.String, boolean)) + * and should not contain database name

* * @param table - table name * @param database - database name @@ -2316,6 +2322,9 @@ public TableSchema getTableSchema(String table, String database) { /** *

Creates table schema from a query.

+ *

Important: table name should be properly escaped + * (see @link com.clickhouse.client.api.sql.SQLUtils#enquoteIdentifier(java.lang.String, boolean)). + * This method doesn't validate or parse the SQL query

* @param sql - SQL query which schema to return * @return table schema for the query */ @@ -2323,6 +2332,15 @@ public TableSchema getTableSchemaFromQuery(String sql) { return getTableSchemaFromQuery(sql, null); } + /** + *

Creates table schema from a query.

+ *

Important: table name should be properly escaped + * (see @link com.clickhouse.client.api.sql.SQLUtils#enquoteIdentifier(java.lang.String, boolean)). + * This method doesn't validate or parse the SQL query

+ * @param sql - SQL query which schema to return + * @param params - server bound parameters + * @return table schema for the query + */ public TableSchema getTableSchemaFromQuery(String sql, Map params) { final String describeQuery = "DESC (" + sql + ")"; return getTableSchemaImpl(describeQuery, null, sql, getDefaultDatabase(), params); diff --git a/client-v2/src/main/java/com/clickhouse/client/api/sql/SQLUtils.java b/client-v2/src/main/java/com/clickhouse/client/api/sql/SQLUtils.java index 99f87f87d..6326e875f 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/sql/SQLUtils.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/sql/SQLUtils.java @@ -6,7 +6,7 @@ public class SQLUtils { /** * Escapes and quotes a string literal for use in SQL queries. - * ClickHouse honours backslash escape sequences inside single-quoted strings, so a backslash + * ClickHouse honors backslash escape sequences inside single-quoted strings, so a backslash * is escaped by doubling it before the single quotes are doubled. Without that, a literal * backslash-t in the input would reach the server as a TAB, and a trailing backslash would * escape the closing quote.