From 7ce16a3431baf5c823f6a996440faff890b56c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cam=20Sa=C3=BCl?= <cammsaul@gmail.com> Date: Tue, 11 Apr 2017 13:59:47 -0700 Subject: [PATCH] Minor code cleanup for #3858 --- src/metabase/driver/crate.clj | 14 +++++++------- src/metabase/util/honeysql_extensions.clj | 12 +++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/metabase/driver/crate.clj b/src/metabase/driver/crate.clj index 89ee9509f84..55082daf911 100644 --- a/src/metabase/driver/crate.clj +++ b/src/metabase/driver/crate.clj @@ -60,17 +60,17 @@ (defn- describe-table-fields [database, driver, {:keys [schema name]}] (let [columns (jdbc/query - (sql/db->jdbc-connection-spec database) - [(format "select column_name, data_type as type_name + (sql/db->jdbc-connection-spec database) + [(format "select column_name, data_type as type_name from information_schema.columns where table_name like '%s' and table_schema like '%s' and data_type != 'object_array'" name schema)])] ; clojure jdbc can't handle fields of type "object_array" atm (set (for [{:keys [column_name type_name]} columns] - (merge {:name column_name - :custom {:column-type type_name} - :base-type (or (column->base-type (keyword type_name)) - (do (log/warn (format "Don't know how to map column type '%s' to a Field base_type, falling back to :type/*." type_name)) - :type/*))}))))) + {:name column_name + :custom {:column-type type_name} + :base-type (or (column->base-type (keyword type_name)) + (do (log/warn (format "Don't know how to map column type '%s' to a Field base_type, falling back to :type/*." type_name)) + :type/*))})))) (defn- add-table-pks [^DatabaseMetaData metadata, table] diff --git a/src/metabase/util/honeysql_extensions.clj b/src/metabase/util/honeysql_extensions.clj index fa95415f634..70bfe6de28e 100644 --- a/src/metabase/util/honeysql_extensions.clj +++ b/src/metabase/util/honeysql_extensions.clj @@ -21,8 +21,10 @@ (intern 'honeysql.format 'quote-fns (assoc quote-fns :h2 (comp s/upper-case ansi-quote-fn)))) + +;; `:crate` quote style that correctly quotes nested column identifiers (defn- str-insert - "Insert c in string s at index i." + "Insert C in string S at index I." [s c i] (str c (subs s 0 i) c (subs s i))) @@ -33,10 +35,10 @@ (str \" s \") (str-insert s "\"" idx)))) -;; `:crate` quote style that correctly quotes nested column identifiers -(let [quote-fns @(resolve 'honeysql.format/quote-fns)] - (->> (assoc quote-fns :crate crate-column-identifier) - (intern 'honeysql.format 'quote-fns))) +(let [quote-fns @(resolve 'honeysql.format/quote-fns)] + (intern 'honeysql.format 'quote-fns + (assoc quote-fns :crate crate-column-identifier))) + ;; register the `extract` function with HoneySQL ;; (hsql/format (hsql/call :extract :a :b)) -> "extract(a from b)" -- GitLab