From 4e395ed3c4c3c3ad6e79dae8d1bfaeee03436d66 Mon Sep 17 00:00:00 2001
From: Gary Fredericks <fredericksgary@gmail.com>
Date: Tue, 22 Jan 2013 10:53:41 -0600
Subject: [PATCH] Create a IResultsetReadColumn protocol for transforming
 types out of the database

By default is the identity, but can be extended by users to deal with
special types (like arrays).
---
 src/main/clojure/clojure/java/jdbc.clj |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main/clojure/clojure/java/jdbc.clj b/src/main/clojure/clojure/java/jdbc.clj
index 24a3156..2ce93b1 100644
--- a/src/main/clojure/clojure/java/jdbc.clj
+++ b/src/main/clojure/clojure/java/jdbc.clj
@@ -239,6 +239,16 @@ generated keys are returned (as a map)." }
     cols
     (reduce (fn [unique-cols col-name] (conj unique-cols (make-name-unique unique-cols col-name 1))) []  cols)))
 
+(defprotocol IResultsetReadColumn
+  (resultset-read-column [_]))
+
+(extend-protocol IResultsetReadColumn
+  Object
+  (resultset-read-column [x] x)
+
+  nil
+  (resultset-read-column [_] nil))
+
 (defn resultset-seq
   "Creates and returns a lazy sequence of maps corresponding to
    the rows in the java.sql.ResultSet rs. Based on clojure.core/resultset-seq
@@ -253,7 +263,7 @@ generated keys are returned (as a map)." }
                  (map (fn [^Integer i] (.getColumnLabel rsmeta i)))
                  make-cols-unique
                  (map (comp keyword identifiers)))
-          row-values (fn [] (map (fn [^Integer i] (.getObject rs i)) idxs))
+          row-values (fn [] (map (fn [^Integer i] (resultset-read-column (.getObject rs i))) idxs))
           ;; This used to use create-struct (on keys) and then struct to populate each row.
           ;; That had the side effect of preserving the order of columns in each row. As
           ;; part of JDBC-15, this was changed because structmaps are deprecated. We don't
-- 
1.7.9.5

