Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; What we're after is pretty-printing a DB result set.
- ;; We need to go through all results before printing to note the maximum width
- ;; of each column, so we can print something like:
- ;;
- ;; +-------+--------------------------------+-------+
- ;; | COL_A | COL_B | COL_C |
- ;; +-------+--------------------------------+-------+
- ;; | foo | Large data so col size expands | bar |
- ;; +-------+--------------------------------+-------+
- ;;
- (defn print-result-set [rs]
- (let [meta-data (.getMetaData rs)]
- (loop [col-widths {}
- current-col 1] ; indexed from 1
- (if (<= current-col (.getColumnCount meta-data))
- (recur (assoc col-widths
- current-col
- (.length (.getColumnName meta-data current-col)))
- (+ 1 current-col))
- (loop [col-widths col-widths
- col-data {}
- next-row (.next rs)]
- (if next-row
- (loop [; go through cols, getting each piece and noting size.
- ; now done with column headers, so process data.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement