Has anybody else hit this?
I just did. Its not tricky to alter resultset-seq to return maps with
qualified keys:
(defn resultset-seq
"Creates and returns a lazy sequence of structmaps corresponding to
the rows in the java.sql.ResultSet rs"
[#^java.sql.ResultSet rs]
(let [rsmeta (. rs (getMetaData))
idxs (range 1 (inc (. rsmeta (getColumnCount))))
keys (map (comp keyword (memfn toLowerCase))
- (map (fn [i] (. rsmeta (getColumnName i))) idxs))
+ (map (fn [i] (str (. rsmeta (getTableName i)) "."
(. rsmeta (getColumnName i)))) idxs))
row-struct (apply create-struct keys)
row-values (fn [] (map (fn [#^Integer i] (. rs (getObject i))) idxs))
rows (fn thisfn []
(when (. rs (next))
(lazy-cons (apply struct row-struct (row-values))
(thisfn))))]
(rows)))
Of course now all keys come back as qualified, breaking anything that
relied on the old behaviour. It also wouldn't be too hard to make this
return qualified keys only when there are duplicate column names, as
demonstrated by Allen.
Another thought I had would be to pass a flag to specify if you want
qualified keys which defaults to false--this way you get the old
behaviour unless you ask for/need qualified keys.
Rich, would you consider a patch to make resultset-seq more robust to
handle cases with duplicate column names?
/mike.