Permalink
Browse files

Merge branch 'master' of github.com:clojure/java.jdbc

  • Loading branch information...
seancorfield committed Aug 12, 2018
2 parents fb5e44a + ee1ebac commit b0c344cf0839b7078ee5c36abaf60fdd73b99632
Showing with 48 additions and 8 deletions.
  1. +4 −0 CHANGES.md
  2. +2 −2 README.md
  3. +11 −5 src/main/clojure/clojure/java/jdbc.clj
  4. +31 −1 src/test/clojure/clojure/java/jdbc_test.clj
View
@@ -1,3 +1,7 @@
Changes coming in 0.7.8
* Allow `with-db-connection` and `with-db-metadata` to nest [JDBC-171](https://dev.clojure.org/jira/browse/JDBC-171).
Changes in 0.7.7
* Support `:as-arrays?`, `:result-set-fn`, and `:row-fn` in operations that return generated keys as a result set (`execute!`, `insert!`, and `insert-multi!`) [JDBC-169](https://dev.clojure.org/jira/browse/JDBC-169).
View
@@ -139,8 +139,8 @@ Change Log
====================
* Release 0.7.7 on 2018-06-23
* Support `:as-arrays?`, `:result-set-fn`, and `:row-fn` in operations that return generated keys as a result set (`execute!`, `insert!`, and `insert-multi!`) [JDBC-169](https://dev.clojure.org/jira/browse/JDBC-169).
* `get-connection` provides much better feedback if you accidentally call a function that expects a `db-spec` but pass a `java.sql.Connection` object instead (which is only required for `prepare-statement`).
* Support `:as-arrays?`, `:result-set-fn`, and `:row-fn` in operations that return generated keys as a result set (`execute!`, `insert!`, and `insert-multi!`) [JDBC-169](https://dev.clojure.org/jira/browse/JDBC-169).
* `get-connection` provides much better feedback if you accidentally call a function that expects a `db-spec` but pass a `java.sql.Connection` object instead (which is only required for `prepare-statement`).
* Release 0.7.6 on 2018-04-24
* `execute!` now supports `:return-keys` as a vector of column names, rather than just a simple Boolean value, for drivers that support that [JDBC-166](https://dev.clojure.org/jira/browse/JDBC-166).
@@ -851,9 +851,12 @@ http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html"}
... con-db ...)"
[binding & body]
`(let [db-spec# ~(second binding) opts# ~(or (second (rest binding)) {})]
(with-open [con# (get-connection db-spec# opts#)]
(let [~(first binding) (add-connection db-spec# con#)]
~@body))))
(if (db-find-connection db-spec#)
(let [~(first binding) db-spec#]
~@body)
(with-open [con# (get-connection db-spec# opts#)]
(let [~(first binding) (add-connection db-spec# con#)]
~@body)))))
(defmacro with-db-metadata
"Evaluates body in the context of an active connection with metadata bound
@@ -863,9 +866,12 @@ http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html"}
... md ...)"
[binding & body]
`(let [db-spec# ~(second binding) opts# ~(or (second (rest binding)) {})]
(with-open [con# (get-connection db-spec# opts#)]
(if-let [con# (db-find-connection db-spec#)]
(let [~(first binding) (.getMetaData con#)]
~@body))))
~@body)
(with-open [con# (get-connection db-spec# opts#)]
(let [~(first binding) (.getMetaData con#)]
~@body)))))
(defn- process-result-set
"Given a Java ResultSet and options, produce a processed result-set-seq,
@@ -590,6 +590,16 @@
(is (= "Pear" (sql/query db ["SELECT * FROM fruit WHERE cost = ?" 99]
{:row-fn :name :result-set-fn first}))))))
(deftest test-nested-with-connection
(doseq [db (test-specs)]
(create-test-table :fruit db)
(sql/with-db-connection [conn1 db]
(sql/query conn1 "select * from fruit")
(sql/with-db-connection [conn2 conn1]
(sql/query conn2 "select * from fruit"))
;; JDBC-171 bug: this blows up because with-db-connection won't nest
(is (= [] (sql/query conn1 "select * from fruit"))))))
(deftest test-update-values
(doseq [db (test-specs)]
(create-test-table :fruit db)
@@ -876,7 +886,27 @@
(is (= "fruit" (-> table-info
first
:table_name
clojure.string/lower-case)))))))
clojure.string/lower-case)))))
(sql/with-db-connection [conn db]
(sql/with-db-metadata [metadata conn {}]
(let [table-info (sql/metadata-query (.getTables metadata
nil nil nil
(into-array ["TABLE" "VIEW"])))]
(is (not= [] table-info))
(is (= "fruit" (-> table-info
first
:table_name
clojure.string/lower-case)))))
;; JDBC-171 this used to blow up because the connnection is closed
(sql/with-db-metadata [metadata conn {}]
(let [table-info (sql/metadata-query (.getTables metadata
nil nil nil
(into-array ["TABLE" "VIEW"])))]
(is (not= [] table-info))
(is (= "fruit" (-> table-info
first
:table_name
clojure.string/lower-case))))))))
(deftest test-metadata-managed-computed
(doseq [db (test-specs)]

0 comments on commit b0c344c

Please sign in to comment.