Created
January 18, 2012 12:22
-
-
Save simonholgate/1632764 to your computer and use it in GitHub Desktop.
clojure.java.jdbc Oracle clob
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
(defn clob-to-string [clob] | |
"Turn an Oracle Clob into a String" | |
(with-open [rdr (java.io.BufferedReader. (.getCharacterStream clob))] | |
(apply str (line-seq rdr)))) | |
(with-connection mydb | |
(transaction | |
(with-query-results rs ["select documentation from station"] | |
; rs will be a sequence of maps, | |
; one for each record in the result set. | |
(doseq [row rs] (println (clob-to-string (:documentation row))))))) | |
(comment "documentation" is stored as an Oracle clob in the table "station". | |
The above works in clojure.java.jdbc if I def mydb. | |
How do I use this with a connection defdb'd in korma?) | |
;; A partial solution: | |
(with-connection (get-connection mydb) | |
(transaction | |
(with-query-results rs ["select documentation from station"] | |
; rs will be a sequence of maps, | |
; one for each record in the result set. | |
(doseq [row rs] (println (clob-to-string (:documentation row))))))) | |
(comment is there a more elegant way to do this?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the latest java.jdbc API (0.6.1 onwards) this whole example would become:
Or if you just wanted to expand the documentation column in the rows: