Fix next.jdbc.date-time for java.sql.Date

An insert fails with
> UnsupportedOperationException: null at java.sql/java.sql.Date.toInstant(Date.java:316)

if you required `next.jdbc.date-time` and the value you are inserting is `java.sql.Date` because it is a subclass of `java.util.Date` and thus gets handled by https://github.com/seancorfield/next-jdbc/blob/master/src/next/jdbc/date_time.clj#L45 - but it doesn't support `toInstant` contrary to its superclass.

The solution is to use `.setDate` with the value as-is instead of `.setTimestamp`.
This commit is contained in:
Jakub Holy 2019-11-18 15:27:11 +01:00 committed by GitHub
parent ef0f33f919
commit 484ed90b7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,4 +44,8 @@
;; this is just to help PostgreSQL: ;; this is just to help PostgreSQL:
java.util.Date java.util.Date
(set-parameter [^java.util.Date v ^PreparedStatement s ^long i] (set-parameter [^java.util.Date v ^PreparedStatement s ^long i]
(.setTimestamp s i (Timestamp/from (.toInstant v))))) (.setTimestamp s i (Timestamp/from (.toInstant v))))
;; ... but leave java.*sql*.Date as-is, it doesn't support toInstant
java.sql.Date
(set-parameter [^java.sql.Date v ^PreparedStatement s ^long i]
(.setDate s i v)))