From 32e9f338d5ad09c1f47aaa960e01931cfc70d02d Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Mon, 18 Nov 2019 09:35:32 -0800 Subject: [PATCH] Addresses #76 by not converting SQL Date/Timestamp types --- CHANGELOG.md | 1 + src/next/jdbc/date_time.clj | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 258eb3a..9297deb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Only accretive/fixative changes will be made from now on. The following changes have been committed to the **master** branch since the 1.0.10 release: +* Fix #76 by avoiding conversions on `java.sql.Date` and `java.sql.Timestamp`. * Add testing against Microsoft SQL Server (run tests with environment variables `NEXT_JDBC_TEST_MSSQL=yes` and `MSSQL_SA_PASSWORD` set to your local -- `127.0.0.1:1433` -- SQL Server `sa` user password; assumes that it can create and drop `fruit` and `fruit_time` tables in the `model` database). * Add testing against MySQL (run tests with environment variables `NEXT_JDBC_TEST_MYSQL=yes` and `MYSQL_ROOT_PASSWORD` set to your local -- `127.0.0.1:3306` -- MySQL `root` user password; assumes you have already created an empty database called `clojure_test`). * Bump several JDBC driver versions for up-to-date testing. diff --git a/src/next/jdbc/date_time.clj b/src/next/jdbc/date_time.clj index 09b20c9..02dd8e2 100644 --- a/src/next/jdbc/date_time.clj +++ b/src/next/jdbc/date_time.clj @@ -30,7 +30,7 @@ (set! *warn-on-reflection* true) (extend-protocol p/SettableParameter - ;; Java Time type conversion + ;; Java Time type conversion: java.time.Instant (set-parameter [^java.time.Instant v ^PreparedStatement s ^long i] (.setTimestamp s i (Timestamp/from v))) @@ -44,4 +44,11 @@ ;; this is just to help PostgreSQL: java.util.Date (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 avoid unnecessary conversions for SQL Date and Timestamp: + java.sql.Date + (set-parameter [^java.sql.Date v ^PreparedStatement s ^long i] + (.setDate s i v)) + java.sql.Timestamp + (set-parameter [^java.sql.Timestamp v ^PreparedStatement s ^long i] + (.setTimestamp s i v)))