Last active
March 2, 2017 13:56
-
-
Save codelahoma/5716957 to your computer and use it in GitHub Desktop.
Using clojure.java.jdbc to process multiple result sets from a SQL Server instance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Does not handle parametized queries for the | |
;; simple reason that I was dealing with a pre-formatted | |
;; string to call a stored procedure. | |
;; | |
;; Feel free to fork and improve. :-) | |
(require '[clojure.java.jdbc :as j] | |
'[clojure.java.jdbc.sql :as s]) | |
(def db {:classname "com.microsoft.jdbc.sqlserver.SQLServerDriver" | |
:subprotocol "sqlserver" | |
:subname (db-connect-string :your-connect-string-here)}) | |
(defn get-multiple-result-sets [cmd] | |
(j/with-connection db | |
(let [stmt (.createStatement (j/connection))] | |
(if (.execute stmt cmd) | |
(loop [rslt (into [] (j/result-set-seq (.getResultSet stmt)))] | |
(if (.getMoreResults stmt) | |
(recur (conj rslt (into [] (j/result-set-seq (.getResultSet stmt))))) | |
rslt)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great stuff, thanks!
The below version will handle parameters,
set-parameters
is just copied from the clojure.java.jdbc source.