Improve printability as part of #51

Since `str` may be able to realize a row and render it as a string, attempts to print a row use this route to circumvent `print-sequential` failing due to lazy evaluation.
This commit is contained in:
Sean Corfield 2019-08-02 12:42:00 -07:00
parent 0fd8bf1a88
commit e0b0c214fd
2 changed files with 13 additions and 5 deletions

View file

@ -373,13 +373,13 @@
(catch Throwable _ (catch Throwable _
"{row} from `plan` -- missing `map` or `reduce`?")))))) "{row} from `plan` -- missing `map` or `reduce`?"))))))
(defmethod print-dup MapifiedResultSet [_ ^java.io.Writer w] (defmethod print-dup MapifiedResultSet [rs ^java.io.Writer w]
(.write w "{row} from `plan` -- missing `map` or `reduce`?")) (.write w (str rs)))
(prefer-method print-dup MapifiedResultSet clojure.lang.IPersistentMap) (prefer-method print-dup MapifiedResultSet clojure.lang.IPersistentMap)
(defmethod print-method MapifiedResultSet [_ ^java.io.Writer w] (defmethod print-method MapifiedResultSet [rs ^java.io.Writer w]
(.write w "{row} from `plan` -- missing `map` or `reduce`?")) (.write w (str rs)))
(prefer-method print-method MapifiedResultSet clojure.lang.IPersistentMap) (prefer-method print-method MapifiedResultSet clojure.lang.IPersistentMap)

View file

@ -165,7 +165,15 @@ VALUES ('Pear', 'green', 49, 47)
(is (re-find #"missing reduction" s))) (is (re-find #"missing reduction" s)))
(let [s (pr-str (into [] (jdbc/plan (ds) ["select * from fruit"])))] (let [s (pr-str (into [] (jdbc/plan (ds) ["select * from fruit"])))]
(is (re-find #"missing `map` or `reduce`" s))) (is (re-find #"missing `map` or `reduce`" s)))
;; this may succeed or not, depending on how the driver handles things
;; most drivers will error because the ResultSet was closed before pr-str
;; is invoked (which will attempt to print each row)
(let [s (pr-str (into [] (take 3) (jdbc/plan (ds) ["select * from fruit"])))] (let [s (pr-str (into [] (take 3) (jdbc/plan (ds) ["select * from fruit"])))]
(is (re-find #"missing `map` or `reduce`" s))) (is (or (re-find #"missing `map` or `reduce`" s)
(re-find #"(?i)^\[#:fruit\{.*:id.*\}\]$" s))))
(is (every? #(re-find #"(?i)^#:fruit\{.*:id.*\}$" %)
(into [] (map str) (jdbc/plan (ds) ["select * from fruit"]))))
(is (every? #(re-find #"(?i)^#:fruit\{.*:id.*\}$" %)
(into [] (map pr-str) (jdbc/plan (ds) ["select * from fruit"]))))
(is (thrown? IllegalArgumentException (is (thrown? IllegalArgumentException
(doall (take 3 (jdbc/plan (ds) ["select * from fruit"])))))) (doall (take 3 (jdbc/plan (ds) ["select * from fruit"]))))))