diff --git a/src/next/jdbc/transaction.clj b/src/next/jdbc/transaction.clj index 84789ac..bb9539f 100644 --- a/src/next/jdbc/transaction.clj +++ b/src/next/jdbc/transaction.clj @@ -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 _)))))))) diff --git a/test/next/jdbc/test_fixtures.clj b/test/next/jdbc/test_fixtures.clj index ec66be9..e67a4f2 100644 --- a/test/next/jdbc/test_fixtures.clj +++ b/test/next/jdbc/test_fixtures.clj @@ -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) diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index 2cc3c26..4d01840 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -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"