2020-01-01 21:13:41 +00:00
|
|
|
;; copyright (c) 2019-2020 Sean Corfield, all rights reserved
|
2019-04-19 05:43:27 +00:00
|
|
|
|
2019-01-08 04:38:58 +00:00
|
|
|
(ns next.jdbc-test
|
2019-11-15 01:10:49 +00:00
|
|
|
"Basic tests for the primary API of `next.jdbc`."
|
2019-10-14 18:13:36 +00:00
|
|
|
(:require [clojure.string :as str]
|
2019-10-02 16:19:31 +00:00
|
|
|
[clojure.test :refer [deftest is testing use-fixtures]]
|
2019-04-20 05:51:48 +00:00
|
|
|
[next.jdbc :as jdbc]
|
2019-10-02 16:19:31 +00:00
|
|
|
[next.jdbc.connection :as c]
|
2019-11-15 23:38:51 +00:00
|
|
|
[next.jdbc.test-fixtures :refer [with-test-db db ds column
|
2020-06-06 01:34:08 +00:00
|
|
|
default-options stored-proc?
|
2019-11-16 06:37:42 +00:00
|
|
|
derby? mssql? mysql? postgres?]]
|
2019-04-20 05:51:48 +00:00
|
|
|
[next.jdbc.prepare :as prep]
|
2019-05-22 04:45:05 +00:00
|
|
|
[next.jdbc.result-set :as rs]
|
|
|
|
|
[next.jdbc.specs :as specs])
|
2019-11-15 01:10:49 +00:00
|
|
|
(:import (java.sql ResultSet)))
|
2019-01-08 04:38:58 +00:00
|
|
|
|
2019-05-29 16:04:21 +00:00
|
|
|
(set! *warn-on-reflection* true)
|
|
|
|
|
|
2019-05-01 23:21:23 +00:00
|
|
|
(use-fixtures :once with-test-db)
|
|
|
|
|
|
2019-05-22 04:45:05 +00:00
|
|
|
(specs/instrument)
|
|
|
|
|
|
2019-04-20 05:51:48 +00:00
|
|
|
(deftest basic-tests
|
2019-05-22 23:22:14 +00:00
|
|
|
(testing "plan"
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (= "Apple"
|
|
|
|
|
(reduce (fn [_ row] (reduced (:name row)))
|
|
|
|
|
nil
|
2019-05-22 23:22:14 +00:00
|
|
|
(jdbc/plan
|
2019-04-20 05:51:48 +00:00
|
|
|
(ds)
|
|
|
|
|
["select * from fruit where appearance = ?" "red"])))))
|
|
|
|
|
(testing "execute-one!"
|
2019-11-01 16:34:14 +00:00
|
|
|
(is (nil? (jdbc/execute-one!
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit where appearance = ?" "neon-green"])))
|
2019-11-15 23:38:51 +00:00
|
|
|
(is (= "Apple" ((column :FRUIT/NAME)
|
2019-04-20 05:51:48 +00:00
|
|
|
(jdbc/execute-one!
|
|
|
|
|
(ds)
|
2019-11-16 06:37:42 +00:00
|
|
|
["select * from fruit where appearance = ?" "red"]
|
|
|
|
|
(default-options))))))
|
2019-04-20 05:51:48 +00:00
|
|
|
(testing "execute!"
|
2019-11-01 16:34:14 +00:00
|
|
|
(let [rs (jdbc/execute!
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit where appearance = ?" "neon-green"])]
|
|
|
|
|
(is (vector? rs))
|
|
|
|
|
(is (= [] rs)))
|
2019-04-20 05:51:48 +00:00
|
|
|
(let [rs (jdbc/execute!
|
|
|
|
|
(ds)
|
2019-11-16 06:37:42 +00:00
|
|
|
["select * from fruit where appearance = ?" "red"]
|
|
|
|
|
(default-options))]
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (= 1 (count rs)))
|
2019-11-15 23:38:51 +00:00
|
|
|
(is (= 1 ((column :FRUIT/ID) (first rs)))))
|
2019-04-20 05:51:48 +00:00
|
|
|
(let [rs (jdbc/execute!
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit order by id"]
|
2019-11-16 06:37:42 +00:00
|
|
|
(assoc (default-options) :builder-fn rs/as-maps))]
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (every? map? rs))
|
|
|
|
|
(is (every? meta rs))
|
|
|
|
|
(is (= 4 (count rs)))
|
2019-11-15 23:38:51 +00:00
|
|
|
(is (= 1 ((column :FRUIT/ID) (first rs))))
|
|
|
|
|
(is (= 4 ((column :FRUIT/ID) (last rs)))))
|
2019-04-20 05:51:48 +00:00
|
|
|
(let [rs (jdbc/execute!
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit order by id"]
|
2019-11-16 06:37:42 +00:00
|
|
|
(assoc (default-options) :builder-fn rs/as-arrays))]
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (every? vector? rs))
|
|
|
|
|
(is (= 5 (count rs)))
|
|
|
|
|
(is (every? #(= 5 (count %)) rs))
|
|
|
|
|
;; columns come first
|
|
|
|
|
(is (every? qualified-keyword? (first rs)))
|
|
|
|
|
;; :FRUIT/ID should be first column
|
2019-11-15 23:38:51 +00:00
|
|
|
(is (= (column :FRUIT/ID) (ffirst rs)))
|
2019-04-20 05:51:48 +00:00
|
|
|
;; and all its corresponding values should be ints
|
|
|
|
|
(is (every? int? (map first (rest rs))))
|
2019-12-20 23:45:22 +00:00
|
|
|
(is (every? string? (map second (rest rs))))))
|
|
|
|
|
(testing "execute! with adapter"
|
2019-08-21 21:47:55 +00:00
|
|
|
(let [rs (jdbc/execute! ; test again, with adapter and lower columns
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit order by id"]
|
2019-11-16 06:37:42 +00:00
|
|
|
(assoc (default-options)
|
|
|
|
|
:builder-fn (rs/as-arrays-adapter
|
|
|
|
|
rs/as-lower-arrays
|
|
|
|
|
(fn [^ResultSet rs _ ^Integer i]
|
|
|
|
|
(.getObject rs i)))))]
|
2019-08-21 21:47:55 +00:00
|
|
|
(is (every? vector? rs))
|
|
|
|
|
(is (= 5 (count rs)))
|
|
|
|
|
(is (every? #(= 5 (count %)) rs))
|
|
|
|
|
;; columns come first
|
|
|
|
|
(is (every? qualified-keyword? (first rs)))
|
|
|
|
|
;; :fruit/id should be first column
|
|
|
|
|
(is (= :fruit/id (ffirst rs)))
|
|
|
|
|
;; and all its corresponding values should be ints
|
|
|
|
|
(is (every? int? (map first (rest rs))))
|
2019-12-20 23:45:22 +00:00
|
|
|
(is (every? string? (map second (rest rs))))))
|
|
|
|
|
(testing "execute! with unqualified"
|
2019-04-20 05:51:48 +00:00
|
|
|
(let [rs (jdbc/execute!
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit order by id"]
|
2019-04-24 21:22:35 +00:00
|
|
|
{:builder-fn rs/as-unqualified-maps})]
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (every? map? rs))
|
|
|
|
|
(is (every? meta rs))
|
|
|
|
|
(is (= 4 (count rs)))
|
2019-11-15 23:38:51 +00:00
|
|
|
(is (= 1 ((column :ID) (first rs))))
|
|
|
|
|
(is (= 4 ((column :ID) (last rs)))))
|
2019-04-20 05:51:48 +00:00
|
|
|
(let [rs (jdbc/execute!
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit order by id"]
|
2019-04-24 21:22:35 +00:00
|
|
|
{:builder-fn rs/as-unqualified-arrays})]
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (every? vector? rs))
|
|
|
|
|
(is (= 5 (count rs)))
|
|
|
|
|
(is (every? #(= 5 (count %)) rs))
|
|
|
|
|
;; columns come first
|
|
|
|
|
(is (every? simple-keyword? (first rs)))
|
|
|
|
|
;; :ID should be first column
|
2019-11-15 23:38:51 +00:00
|
|
|
(is (= (column :ID) (ffirst rs)))
|
2019-04-20 05:51:48 +00:00
|
|
|
;; and all its corresponding values should be ints
|
|
|
|
|
(is (every? int? (map first (rest rs))))
|
|
|
|
|
(is (every? string? (map second (rest rs))))))
|
2019-12-20 23:45:22 +00:00
|
|
|
(testing "execute! with :max-rows / :maxRows"
|
|
|
|
|
(let [rs (jdbc/execute!
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit order by id"]
|
|
|
|
|
(assoc (default-options) :max-rows 2))]
|
|
|
|
|
(is (every? map? rs))
|
|
|
|
|
(is (every? meta rs))
|
|
|
|
|
(is (= 2 (count rs)))
|
|
|
|
|
(is (= 1 ((column :FRUIT/ID) (first rs))))
|
|
|
|
|
(is (= 2 ((column :FRUIT/ID) (last rs)))))
|
|
|
|
|
(let [rs (jdbc/execute!
|
|
|
|
|
(ds)
|
|
|
|
|
["select * from fruit order by id"]
|
|
|
|
|
(assoc (default-options) :statement {:maxRows 2}))]
|
|
|
|
|
(is (every? map? rs))
|
|
|
|
|
(is (every? meta rs))
|
|
|
|
|
(is (= 2 (count rs)))
|
|
|
|
|
(is (= 1 ((column :FRUIT/ID) (first rs))))
|
|
|
|
|
(is (= 2 ((column :FRUIT/ID) (last rs))))))
|
2019-04-20 05:51:48 +00:00
|
|
|
(testing "prepare"
|
2019-07-09 03:48:56 +00:00
|
|
|
(let [rs (with-open [con (jdbc/get-connection (ds))
|
|
|
|
|
ps (jdbc/prepare
|
|
|
|
|
con
|
2019-11-16 06:37:42 +00:00
|
|
|
["select * from fruit order by id"]
|
|
|
|
|
(default-options))]
|
2019-07-09 03:48:56 +00:00
|
|
|
(jdbc/execute! ps))]
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (every? map? rs))
|
|
|
|
|
(is (every? meta rs))
|
|
|
|
|
(is (= 4 (count rs)))
|
2019-11-15 23:38:51 +00:00
|
|
|
(is (= 1 ((column :FRUIT/ID) (first rs))))
|
|
|
|
|
(is (= 4 ((column :FRUIT/ID) (last rs)))))
|
2019-07-09 03:48:56 +00:00
|
|
|
(let [rs (with-open [con (jdbc/get-connection (ds))
|
|
|
|
|
ps (jdbc/prepare
|
|
|
|
|
con
|
2019-11-16 06:37:42 +00:00
|
|
|
["select * from fruit where id = ?"]
|
|
|
|
|
(default-options))]
|
2019-11-15 00:15:52 +00:00
|
|
|
(jdbc/execute! (prep/set-parameters ps [4]) nil {}))]
|
|
|
|
|
(is (every? map? rs))
|
|
|
|
|
(is (every? meta rs))
|
|
|
|
|
(is (= 1 (count rs)))
|
2019-11-15 23:38:51 +00:00
|
|
|
(is (= 4 ((column :FRUIT/ID) (first rs))))))
|
2019-11-15 00:15:52 +00:00
|
|
|
(testing "statement"
|
|
|
|
|
(let [rs (with-open [con (jdbc/get-connection (ds))]
|
2019-12-20 23:45:22 +00:00
|
|
|
(jdbc/execute! (prep/statement con (default-options))
|
2019-11-15 00:15:52 +00:00
|
|
|
["select * from fruit order by id"]))]
|
|
|
|
|
(is (every? map? rs))
|
|
|
|
|
(is (every? meta rs))
|
|
|
|
|
(is (= 4 (count rs)))
|
2019-12-20 23:45:22 +00:00
|
|
|
(is (= 1 ((column :FRUIT/ID) (first rs))))
|
|
|
|
|
(is (= 4 ((column :FRUIT/ID) (last rs)))))
|
2019-11-15 00:15:52 +00:00
|
|
|
(let [rs (with-open [con (jdbc/get-connection (ds))]
|
2019-12-20 23:45:22 +00:00
|
|
|
(jdbc/execute! (prep/statement con (default-options))
|
2019-11-15 00:15:52 +00:00
|
|
|
["select * from fruit where id = 4"]))]
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (every? map? rs))
|
|
|
|
|
(is (every? meta rs))
|
|
|
|
|
(is (= 1 (count rs)))
|
2019-12-20 23:45:22 +00:00
|
|
|
(is (= 4 ((column :FRUIT/ID) (first rs))))))
|
2019-04-20 05:51:48 +00:00
|
|
|
(testing "transact"
|
|
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/transact (ds)
|
|
|
|
|
(fn [t] (jdbc/execute! t ["
|
2019-04-22 00:10:29 +00:00
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
2019-04-20 05:51:48 +00:00
|
|
|
"]))
|
|
|
|
|
{:rollback-only true})))
|
|
|
|
|
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))))
|
2019-07-02 23:45:48 +00:00
|
|
|
(testing "with-transaction rollback-only"
|
2019-04-20 05:51:48 +00:00
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/with-transaction [t (ds) {:rollback-only true}]
|
|
|
|
|
(jdbc/execute! t ["
|
2019-04-22 00:10:29 +00:00
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
2019-04-20 05:51:48 +00:00
|
|
|
"]))))
|
2019-12-12 00:03:41 +00:00
|
|
|
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))
|
|
|
|
|
(with-open [con (jdbc/get-connection (ds))]
|
|
|
|
|
(let [ac (.getAutoCommit con)]
|
|
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/with-transaction [t con {:rollback-only true}]
|
|
|
|
|
(jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"]))))
|
|
|
|
|
(is (= 4 (count (jdbc/execute! con ["select * from fruit"]))))
|
|
|
|
|
(is (= ac (.getAutoCommit con))))))
|
2019-07-02 23:45:48 +00:00
|
|
|
(testing "with-transaction exception"
|
|
|
|
|
(is (thrown? Throwable
|
|
|
|
|
(jdbc/with-transaction [t (ds)]
|
|
|
|
|
(jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"])
|
|
|
|
|
(throw (ex-info "abort" {})))))
|
2019-12-12 00:03:41 +00:00
|
|
|
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))
|
|
|
|
|
(with-open [con (jdbc/get-connection (ds))]
|
|
|
|
|
(let [ac (.getAutoCommit con)]
|
|
|
|
|
(is (thrown? Throwable
|
|
|
|
|
(jdbc/with-transaction [t con]
|
|
|
|
|
(jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"])
|
|
|
|
|
(throw (ex-info "abort" {})))))
|
|
|
|
|
(is (= 4 (count (jdbc/execute! con ["select * from fruit"]))))
|
|
|
|
|
(is (= ac (.getAutoCommit con))))))
|
2019-07-02 23:45:48 +00:00
|
|
|
(testing "with-transaction call rollback"
|
|
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/with-transaction [t (ds)]
|
|
|
|
|
(let [result (jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"])]
|
|
|
|
|
(.rollback t)
|
|
|
|
|
result))))
|
2019-12-12 00:03:41 +00:00
|
|
|
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))
|
|
|
|
|
(with-open [con (jdbc/get-connection (ds))]
|
|
|
|
|
(let [ac (.getAutoCommit con)]
|
|
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/with-transaction [t con]
|
|
|
|
|
(let [result (jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"])]
|
|
|
|
|
(.rollback t)
|
|
|
|
|
result))))
|
|
|
|
|
(is (= 4 (count (jdbc/execute! con ["select * from fruit"]))))
|
|
|
|
|
(is (= ac (.getAutoCommit con))))))
|
2019-07-03 01:36:00 +00:00
|
|
|
(testing "with-transaction with unnamed save point"
|
|
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/with-transaction [t (ds)]
|
|
|
|
|
(let [save-point (.setSavepoint t)
|
|
|
|
|
result (jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"])]
|
|
|
|
|
(.rollback t save-point)
|
|
|
|
|
result))))
|
2019-12-12 00:03:41 +00:00
|
|
|
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))
|
|
|
|
|
(with-open [con (jdbc/get-connection (ds))]
|
|
|
|
|
(let [ac (.getAutoCommit con)]
|
|
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/with-transaction [t con]
|
|
|
|
|
(let [save-point (.setSavepoint t)
|
|
|
|
|
result (jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"])]
|
|
|
|
|
(.rollback t save-point)
|
|
|
|
|
result))))
|
|
|
|
|
(is (= 4 (count (jdbc/execute! con ["select * from fruit"]))))
|
|
|
|
|
(is (= ac (.getAutoCommit con))))))
|
2019-07-03 01:36:00 +00:00
|
|
|
(testing "with-transaction with named save point"
|
|
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/with-transaction [t (ds)]
|
|
|
|
|
(let [save-point (.setSavepoint t (name (gensym)))
|
|
|
|
|
result (jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"])]
|
|
|
|
|
(.rollback t save-point)
|
|
|
|
|
result))))
|
2019-12-12 00:03:41 +00:00
|
|
|
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))
|
|
|
|
|
(with-open [con (jdbc/get-connection (ds))]
|
|
|
|
|
(let [ac (.getAutoCommit con)]
|
|
|
|
|
(is (= [{:next.jdbc/update-count 1}]
|
|
|
|
|
(jdbc/with-transaction [t con]
|
|
|
|
|
(let [save-point (.setSavepoint t (name (gensym)))
|
|
|
|
|
result (jdbc/execute! t ["
|
|
|
|
|
INSERT INTO fruit (name, appearance, cost, grade)
|
|
|
|
|
VALUES ('Pear', 'green', 49, 47)
|
|
|
|
|
"])]
|
|
|
|
|
(.rollback t save-point)
|
|
|
|
|
result))))
|
|
|
|
|
(is (= 4 (count (jdbc/execute! con ["select * from fruit"]))))
|
|
|
|
|
(is (= ac (.getAutoCommit con)))))))
|
2019-06-11 23:47:58 +00:00
|
|
|
|
2019-10-02 16:19:31 +00:00
|
|
|
(deftest connection-tests
|
|
|
|
|
(testing "datasource via jdbcUrl"
|
|
|
|
|
(when-not (postgres?)
|
|
|
|
|
(let [[url etc] (#'c/spec->url+etc (db))
|
|
|
|
|
ds (jdbc/get-datasource (assoc etc :jdbcUrl url))]
|
2019-11-15 23:38:51 +00:00
|
|
|
(cond (derby?) (is (= {:create true} etc))
|
2019-11-16 06:37:42 +00:00
|
|
|
(mssql?) (is (= #{:user :password} (set (keys etc))))
|
2020-03-16 22:19:21 +00:00
|
|
|
(mysql?) (is (= #{:user :password :useSSL}
|
|
|
|
|
(disj (set (keys etc)) :disableMariaDbDriver)))
|
2019-11-15 23:38:51 +00:00
|
|
|
:else (is (= {} etc)))
|
2019-10-02 16:19:31 +00:00
|
|
|
(is (instance? javax.sql.DataSource ds))
|
2019-11-16 06:37:42 +00:00
|
|
|
(is (str/index-of (pr-str ds) (str "jdbc:"
|
2020-06-06 01:34:08 +00:00
|
|
|
(condp = (:dbtype (db))
|
|
|
|
|
"mssql" "sqlserver"
|
|
|
|
|
"jtds" "jtds:sqlserver"
|
|
|
|
|
(:dbtype (db))))))
|
2019-10-02 16:19:31 +00:00
|
|
|
;; checks get-datasource on a DataSource is identity
|
|
|
|
|
(is (identical? ds (jdbc/get-datasource ds)))
|
|
|
|
|
(with-open [con (jdbc/get-connection ds {})]
|
|
|
|
|
(is (instance? java.sql.Connection con)))))))
|
|
|
|
|
|
2020-06-06 01:34:08 +00:00
|
|
|
(deftest multi-rs
|
|
|
|
|
(when (stored-proc?)
|
|
|
|
|
(testing "stored proc; multiple result sets"
|
|
|
|
|
(try
|
2020-06-06 16:32:03 +00:00
|
|
|
(println "====" (:dbtype (db)) "====")
|
2020-06-06 01:34:08 +00:00
|
|
|
(clojure.pprint/pprint
|
2020-06-06 16:32:03 +00:00
|
|
|
(jdbc/execute! (ds) [(if (mssql?) "EXEC FRUITP" "CALL FRUITP()")]
|
|
|
|
|
{:multi-rs true}))
|
2020-06-06 01:34:08 +00:00
|
|
|
(catch Throwable t
|
|
|
|
|
(println 'call-proc (:dbtype (db)) (ex-message t) (some-> t (ex-cause) (ex-message))))))))
|
|
|
|
|
|
|
|
|
|
|
2019-06-11 23:47:58 +00:00
|
|
|
(deftest plan-misuse
|
|
|
|
|
(let [s (pr-str (jdbc/plan (ds) ["select * from fruit"]))]
|
|
|
|
|
(is (re-find #"missing reduction" s)))
|
|
|
|
|
(let [s (pr-str (into [] (jdbc/plan (ds) ["select * from fruit"])))]
|
|
|
|
|
(is (re-find #"missing `map` or `reduce`" s)))
|
2019-08-02 19:42:00 +00:00
|
|
|
;; 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)
|
2019-11-16 06:37:42 +00:00
|
|
|
(let [s (pr-str (into [] (take 3) (jdbc/plan (ds) ["select * from fruit"]
|
|
|
|
|
(default-options))))]
|
2019-08-02 19:42:00 +00:00
|
|
|
(is (or (re-find #"missing `map` or `reduce`" s)
|
|
|
|
|
(re-find #"(?i)^\[#:fruit\{.*:id.*\}\]$" s))))
|
|
|
|
|
(is (every? #(re-find #"(?i)^#:fruit\{.*:id.*\}$" %)
|
2019-11-16 06:37:42 +00:00
|
|
|
(into [] (map str) (jdbc/plan (ds) ["select * from fruit"]
|
|
|
|
|
(default-options)))))
|
2019-08-02 19:42:00 +00:00
|
|
|
(is (every? #(re-find #"(?i)^#:fruit\{.*:id.*\}$" %)
|
2019-11-16 06:37:42 +00:00
|
|
|
(into [] (map pr-str) (jdbc/plan (ds) ["select * from fruit"]
|
|
|
|
|
(default-options)))))
|
2019-06-11 23:47:58 +00:00
|
|
|
(is (thrown? IllegalArgumentException
|
|
|
|
|
(doall (take 3 (jdbc/plan (ds) ["select * from fruit"]))))))
|