From 9e21460cbbd5d84f8572041513b70b4d75f251bb Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 31 Jul 2022 15:29:14 -0700 Subject: [PATCH] fix #208 by turning unsupported into "" --- CHANGELOG.md | 3 +++ src/next/jdbc/result_set.clj | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46f540b..be89503 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Only accretive/fixative changes will be made from now on. +* 1.2.next in progress + * Fix [#208](https://github.com/seancorfield/next-jdbc/issues/208) by treating unsupported exception as an empty string, just like the JDBC docs say should happen. + * 1.2.790 -- 2022-07-29 * Address [#207](https://github.com/seancorfield/next-jdbc/issues/207) by supporting "db-spec" hash maps containing `:datasource` or `:connection-uri` (this is otherwise undocumented and intended to aid migration from `clojure.java.jdbc`). * Address [#199](https://github.com/seancorfield/next-jdbc/issues/199) by adding notes on UTC usage -- [@denismccarthykerry](https://github.com/denismccarthykerry). diff --git a/src/next/jdbc/result_set.clj b/src/next/jdbc/result_set.clj index 3ef5193..0fa0d6f 100644 --- a/src/next/jdbc/result_set.clj +++ b/src/next/jdbc/result_set.clj @@ -33,12 +33,21 @@ (set! *warn-on-reflection* true) +(defn- get-table-name + "No, if it isn't supported, you're supposed to return + an empty string. That's what the JDBC docs say!" + [^ResultSetMetaData rsmeta ^Integer i] + (try + (.getTableName rsmeta i) + (catch java.sql.SQLFeatureNotSupportedException _ + ""))) + (defn get-column-names "Given `ResultSetMetaData`, return a vector of column names, each qualified by the table from which it came." [^ResultSetMetaData rsmeta _] (mapv (fn [^Integer i] - (if-let [q (not-empty (.getTableName rsmeta i))] + (if-let [q (not-empty (get-table-name rsmeta i))] (keyword q (.getColumnLabel rsmeta i)) (keyword (.getColumnLabel rsmeta i)))) (range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0))))) @@ -60,7 +69,7 @@ (assert qf ":qualifier-fn is required") (assert lf ":label-fn is required") (mapv (fn [^Integer i] - (if-let [q (some-> (.getTableName rsmeta i) (qf) (not-empty))] + (if-let [q (some-> (get-table-name rsmeta i) (qf) (not-empty))] (keyword q (-> (.getColumnLabel rsmeta i) (lf))) (keyword (-> (.getColumnLabel rsmeta i) (lf))))) (range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0))))))