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!
|
||||
(when isolation
|
||||
(.setTransactionIsolation con (isolation isolation-levels)))
|
||||
(when read-only
|
||||
(.setReadOnly con true))
|
||||
(when (contains? opts :read-only)
|
||||
(.setReadOnly con (boolean read-only)))
|
||||
(.setAutoCommit con false)
|
||||
(try
|
||||
(let [result (f con)]
|
||||
|
|
@ -107,7 +107,7 @@
|
|||
(try
|
||||
(.setTransactionIsolation con old-isolation)
|
||||
(catch Exception _)))
|
||||
(when read-only
|
||||
(when (contains? opts :read-only)
|
||||
(try
|
||||
(.setReadOnly con old-readonly)
|
||||
(catch Exception _))))))))
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@
|
|||
|
||||
(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]
|
||||
(let [n (namespace k)]
|
||||
(keyword (when n (cond (postgres?) (str/lower-case n)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
[next.jdbc.connection :as c]
|
||||
[next.jdbc.test-fixtures
|
||||
: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?]]
|
||||
[next.jdbc.prepare :as prep]
|
||||
[next.jdbc.result-set :as rs]
|
||||
|
|
@ -821,6 +821,15 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
|
|||
(with-open [con (jdbc/get-connection ds {})]
|
||||
(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
|
||||
(when (mssql?)
|
||||
(testing "script with multiple result sets"
|
||||
|
|
|
|||
Loading…
Reference in a new issue