layerware / hugsql

A Clojure library for embracing SQL
https://hugsql.org
Apache License 2.0
690 stars 54 forks source link

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

Closed kanwei closed 8 years ago

kanwei commented 8 years ago

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.

csummers commented 8 years ago

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!

csummers commented 8 years ago

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.

kanwei commented 8 years ago

It works. Thanks for the quick fix!

csummers commented 8 years ago

You're welcome! Thanks for reporting the issue.