jtds and dealing with nvarchar(max) and ClobImpl

761 views
Skip to first unread message

Oliver George

unread,
May 29, 2014, 8:17:34 PM5/29/14
to sqlk...@googlegroups.com
Hi All

I'm experimenting with Korma querying a SQL Server database using jtds.

My select queries are coming back with net.sourceforge.jtds.jdbc.ClobImpl classes where the field is defined as nvarchar(max) where I would expect a string.  It's not terrible but an extra thing to coerce before using my results.

Below is my first hack at a solution.  I'm posting here in case there's a better way I'm missing.

The only real pain is that I need to add a transform to every (defentity ...) I define.  Perhaps there's a better way.

(defn fmap [f m]
  (into (empty m) (for [[k v] m] [k (f v)])))

(defprotocol IAsNative
  "Load data as native clojure type"
  (as-native [o]))

(extend-protocol IAsNative
  
  net.sourceforge.jtds.jdbc.ClobImpl 
  (as-native [o] (-> o (.getCharacterStream) slurp))
  
  Object 
  (as-native [o] o)
  
  nil
  (as-native [o] nil))

(defentity Users
  (pk :UserId)
  (transform (fn [m] (fmap as-native m))))

It's possible that the Microsoft driver is better.  I might be making trouble for myself by not using it.

cheers, Oliver


Immo Heikkinen

unread,
May 30, 2014, 6:41:25 AM5/30/14
to sqlk...@googlegroups.com
According to http://technet.microsoft.com/en-us/library/ms378878(v=sql.110).aspx Microsoft driver should map nvarchar(max) to String.


--
You received this message because you are subscribed to the Google Groups "Korma" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlkorma+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oliver George

unread,
Jun 1, 2014, 11:52:55 PM6/1/14
to sqlk...@googlegroups.com
Thanks.  You're right.

I setup a local maven repo and tried out the Microsoft driver.  As per that docs link it does return a string so it seems like a JTDS specific issue.




--
You received this message because you are subscribed to a topic in the Google Groups "Korma" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlkorma/pyHvX9C_f4I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlkorma+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Oliver George
Director, Condense
0428 740 978

Oliver George

unread,
Jun 2, 2014, 12:01:57 AM6/2/14
to sqlkorma
Quick follow-up for posterity.  There is an option to stop it using "lobs"...  useLobs=false

So the basic clojure.java.jdbc db config might look like:

(def db {:subprotocol "jtds:sqlserver"
         :subname "//myhost:1433/mydb"
         :user "myuser"
         :password "mypass"
         :useLobs true})

Refs


Reply all
Reply to author
Forward
0 new messages