always call setReadOnly when opening a transaction:
if the connection is read-only and the user supplies `{:read-only false}` as tx opts, we should call `(.setReadOnly conn false)` when we open the transaction, and reset it afterwards
This commit is contained in:
parent
65b26a0fa4
commit
61471aae22
3 changed files with 15 additions and 4 deletions
|
|
@ -65,8 +65,8 @@
|
||||||
(io!
|
(io!
|
||||||
(when isolation
|
(when isolation
|
||||||
(.setTransactionIsolation con (isolation isolation-levels)))
|
(.setTransactionIsolation con (isolation isolation-levels)))
|
||||||
(when read-only
|
(when (contains? opts :read-only)
|
||||||
(.setReadOnly con true))
|
(.setReadOnly con (boolean read-only)))
|
||||||
(.setAutoCommit con false)
|
(.setAutoCommit con false)
|
||||||
(try
|
(try
|
||||||
(let [result (f con)]
|
(let [result (f con)]
|
||||||
|
|
@ -107,7 +107,7 @@
|
||||||
(try
|
(try
|
||||||
(.setTransactionIsolation con old-isolation)
|
(.setTransactionIsolation con old-isolation)
|
||||||
(catch Exception _)))
|
(catch Exception _)))
|
||||||
(when read-only
|
(when (contains? opts :read-only)
|
||||||
(try
|
(try
|
||||||
(.setReadOnly con old-readonly)
|
(.setReadOnly con old-readonly)
|
||||||
(catch Exception _))))))))
|
(catch Exception _))))))))
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,8 @@
|
||||||
|
|
||||||
(defn stored-proc? [] (not (#{"derby" "h2" "h2:mem" "sqlite"} (:dbtype @test-db-spec))))
|
(defn stored-proc? [] (not (#{"derby" "h2" "h2:mem" "sqlite"} (:dbtype @test-db-spec))))
|
||||||
|
|
||||||
|
(defn can-set-read-only? [] (not (#{"h2" "h2:mem" "sqlite"} (:dbtype @test-db-spec))))
|
||||||
|
|
||||||
(defn column [k]
|
(defn column [k]
|
||||||
(let [n (namespace k)]
|
(let [n (namespace k)]
|
||||||
(keyword (when n (cond (postgres?) (str/lower-case n)
|
(keyword (when n (cond (postgres?) (str/lower-case n)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
[next.jdbc.connection :as c]
|
[next.jdbc.connection :as c]
|
||||||
[next.jdbc.test-fixtures
|
[next.jdbc.test-fixtures
|
||||||
:refer [with-test-db db ds column
|
:refer [with-test-db db ds column
|
||||||
default-options stored-proc?
|
default-options stored-proc? can-set-read-only?
|
||||||
derby? hsqldb? jtds? mssql? mysql? postgres? sqlite?]]
|
derby? hsqldb? jtds? mssql? mysql? postgres? sqlite?]]
|
||||||
[next.jdbc.prepare :as prep]
|
[next.jdbc.prepare :as prep]
|
||||||
[next.jdbc.result-set :as rs]
|
[next.jdbc.result-set :as rs]
|
||||||
|
|
@ -821,6 +821,15 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
|
||||||
(with-open [con (jdbc/get-connection ds {})]
|
(with-open [con (jdbc/get-connection ds {})]
|
||||||
(is (instance? java.sql.Connection con)))))))
|
(is (instance? java.sql.Connection con)))))))
|
||||||
|
|
||||||
|
(deftest always-call-set-read-only-when-opening-a-tx
|
||||||
|
(when (can-set-read-only?)
|
||||||
|
(with-open [con (jdbc/get-connection (ds))]
|
||||||
|
(.setReadOnly con true)
|
||||||
|
(jdbc/with-transaction [tx con {:read-only false}]
|
||||||
|
(is (not (.isReadOnly con)))
|
||||||
|
(is (not (.isReadOnly tx))))
|
||||||
|
(is (.isReadOnly con)))))
|
||||||
|
|
||||||
(deftest multi-rs
|
(deftest multi-rs
|
||||||
(when (mssql?)
|
(when (mssql?)
|
||||||
(testing "script with multiple result sets"
|
(testing "script with multiple result sets"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue