Clean up multi-rs results
Accept that PostgreSQL does not support this yet.
This commit is contained in:
parent
9d6e7ab145
commit
0cfbb58b2e
2 changed files with 28 additions and 10 deletions
|
|
@ -55,6 +55,8 @@
|
||||||
|
|
||||||
(defn derby? [] (= "derby" (:dbtype @test-db-spec)))
|
(defn derby? [] (= "derby" (:dbtype @test-db-spec)))
|
||||||
|
|
||||||
|
(defn hsqldb? [] (= "hsqldb" (:dbtype @test-db-spec)))
|
||||||
|
|
||||||
(defn jtds? [] (= "jtds" (:dbtype @test-db-spec)))
|
(defn jtds? [] (= "jtds" (:dbtype @test-db-spec)))
|
||||||
|
|
||||||
(defn maria? [] (= "mariadb" (:dbtype @test-db-spec)))
|
(defn maria? [] (= "mariadb" (:dbtype @test-db-spec)))
|
||||||
|
|
@ -120,7 +122,7 @@
|
||||||
(reset! test-datasource (jdbc/get-datasource db)))
|
(reset! test-datasource (jdbc/get-datasource db)))
|
||||||
(let [fruit (if (mysql?) "fruit" "FRUIT") ; MySQL is case sensitive!
|
(let [fruit (if (mysql?) "fruit" "FRUIT") ; MySQL is case sensitive!
|
||||||
auto-inc-pk
|
auto-inc-pk
|
||||||
(cond (or (derby?) (= "hsqldb" (:dbtype db)))
|
(cond (or (derby?) (hsqldb?))
|
||||||
(str "GENERATED ALWAYS AS IDENTITY"
|
(str "GENERATED ALWAYS AS IDENTITY"
|
||||||
" (START WITH 1, INCREMENT BY 1)"
|
" (START WITH 1, INCREMENT BY 1)"
|
||||||
" PRIMARY KEY")
|
" PRIMARY KEY")
|
||||||
|
|
@ -165,11 +167,11 @@ CREATE TABLE " fruit " (
|
||||||
(let [[begin end] (if (postgres?) ["$$" "$$"] ["BEGIN" "END"])]
|
(let [[begin end] (if (postgres?) ["$$" "$$"] ["BEGIN" "END"])]
|
||||||
(try
|
(try
|
||||||
(do-commands con [(str "
|
(do-commands con [(str "
|
||||||
CREATE PROCEDURE FRUITP" (cond (= "hsqldb" (:dbtype db)) "() READS SQL DATA DYNAMIC RESULT SETS 2 "
|
CREATE PROCEDURE FRUITP" (cond (hsqldb?) "() READS SQL DATA DYNAMIC RESULT SETS 2 "
|
||||||
(mssql?) " AS "
|
(mssql?) " AS "
|
||||||
(postgres?) "() LANGUAGE SQL AS "
|
(postgres?) "() LANGUAGE SQL AS "
|
||||||
:else "() ") "
|
:else "() ") "
|
||||||
" begin " " (if (= "hsqldb" (:dbtype db))
|
" begin " " (if (hsqldb?)
|
||||||
(str "ATOMIC
|
(str "ATOMIC
|
||||||
DECLARE result1 CURSOR WITH RETURN FOR SELECT * FROM " fruit " WHERE COST < 90;
|
DECLARE result1 CURSOR WITH RETURN FOR SELECT * FROM " fruit " WHERE COST < 90;
|
||||||
DECLARE result2 CURSOR WITH RETURN FOR SELECT * FROM " fruit " WHERE GRADE >= 90.0;
|
DECLARE result2 CURSOR WITH RETURN FOR SELECT * FROM " fruit " WHERE GRADE >= 90.0;
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,10 @@
|
||||||
[clojure.test :refer [deftest is testing use-fixtures]]
|
[clojure.test :refer [deftest is testing use-fixtures]]
|
||||||
[next.jdbc :as jdbc]
|
[next.jdbc :as jdbc]
|
||||||
[next.jdbc.connection :as c]
|
[next.jdbc.connection :as c]
|
||||||
[next.jdbc.test-fixtures :refer [with-test-db db ds column
|
[next.jdbc.test-fixtures
|
||||||
default-options stored-proc?
|
:refer [with-test-db db ds column
|
||||||
derby? jtds? mssql? mysql? postgres?]]
|
default-options stored-proc?
|
||||||
|
derby? hsqldb? jtds? mssql? mysql? postgres?]]
|
||||||
[next.jdbc.prepare :as prep]
|
[next.jdbc.prepare :as prep]
|
||||||
[next.jdbc.result-set :as rs]
|
[next.jdbc.result-set :as rs]
|
||||||
[next.jdbc.specs :as specs])
|
[next.jdbc.specs :as specs])
|
||||||
|
|
@ -320,10 +321,25 @@ VALUES ('Pear', 'green', 49, 47)
|
||||||
(when (stored-proc?)
|
(when (stored-proc?)
|
||||||
(testing "stored proc; multiple result sets"
|
(testing "stored proc; multiple result sets"
|
||||||
(try
|
(try
|
||||||
(println "====" (:dbtype (db)) "====")
|
(let [multi-rs
|
||||||
(clojure.pprint/pprint
|
(jdbc/execute! (ds)
|
||||||
(jdbc/execute! (ds) [(if (mssql?) "EXEC FRUITP" "CALL FRUITP()")]
|
[(if (mssql?) "EXEC FRUITP" "CALL FRUITP()")]
|
||||||
{:multi-rs true}))
|
{:multi-rs true})
|
||||||
|
zero-updates [{:next.jdbc/update-count 0}]]
|
||||||
|
(cond (postgres?) ; does not support multiple result sets yet
|
||||||
|
(do
|
||||||
|
(is (= 1 (count multi-rs)))
|
||||||
|
(is (= zero-updates (first multi-rs))))
|
||||||
|
(hsqldb?)
|
||||||
|
(do
|
||||||
|
(is (= 3 (count multi-rs)))
|
||||||
|
(is (= zero-updates (first multi-rs))))
|
||||||
|
(mysql?)
|
||||||
|
(do
|
||||||
|
(is (= 3 (count multi-rs)))
|
||||||
|
(is (= zero-updates (last multi-rs))))
|
||||||
|
:else
|
||||||
|
(is (= 2 (count multi-rs)))))
|
||||||
(catch Throwable t
|
(catch Throwable t
|
||||||
(println 'call-proc (:dbtype (db)) (ex-message t) (some-> t (ex-cause) (ex-message))))))))
|
(println 'call-proc (:dbtype (db)) (ex-message t) (some-> t (ex-cause) (ex-message))))))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue