layerware/hugsql

extend-protocol clojure.java.jdbc/ISQLParameter doesn't work

kanwei opened this issue · 4 comments

Trying to insert/update Postgres arrays from Clojure vectors. With korma and yesql, all I had to do was:

(extend-protocol clojure.java.jdbc/ISQLParameter
  clojure.lang.IPersistentVector
  (set-parameter [v ^java.sql.PreparedStatement stmt ^long i]
    (let [conn (.getConnection stmt)
          meta (.getParameterMetaData stmt)
          type-name (.getParameterTypeName meta i)]
      (.setObject stmt i (.createArrayOf conn (clojure.string/replace type-name #"[^A-Za-z]" "") (to-array v))))))

Hugsql doesn't seem to go through this part of JDBC and seems to always use a string instead of the array.

That's a bug and I think I've fixed this in master. This will roll into the 0.4.4 release a bit later today. Thanks for the report!

I just released 0.4.4 with this fix. Please let me know if the issue is resolved for you. Thanks again for the report.

For those following along, the bug had to do with a vector passed in as parameter data being flattened before it reached the underlying database library, so there was no vector to override.

It works. Thanks for the quick fix!

You're welcome! Thanks for reporting the issue.