Skip to content

Commit

Permalink
Merge pull request #7 from swisscom-bigdata/fix/zoned_date_parameters
Browse files Browse the repository at this point in the history
Fix for PreparedStatement parameter setting
  • Loading branch information
tsadauskas authored May 1, 2020
2 parents 95db29e + 13210ea commit 8055d13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject metabase/teradata-driver "1.0.0-metabase-v0.34.1-teradata-jdbc-16.20"
(defproject metabase/teradata-driver "1.0.1-metabase-v0.34.1-teradata-jdbc-16.20"
:min-lein-version "2.5.0"

:profiles
Expand Down
17 changes: 12 additions & 5 deletions src/metabase/driver/teradata.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[string :as s]]
[clojure.java.jdbc :as jdbc]
[honeysql.core :as hsql]
[java-time :as t]
[metabase
[driver :as driver]
[util :as u]]
Expand All @@ -14,13 +15,12 @@
[sync :as sql-jdbc.sync]]
[metabase.driver.sql.query-processor :as sql.qp]
[metabase.driver.sql.util.deduplicate :as deduplicateutil]
[metabase.models.field :as field]
[metabase.query-processor.util :as qputil]
[metabase.util
[honeysql-extensions :as hx]
[ssh :as ssh]])
(:import [java.sql DatabaseMetaData ResultSet ResultSetMetaData Time Types]
[java.time LocalDate LocalDateTime LocalTime OffsetDateTime OffsetTime ZonedDateTime]))
[honeysql-extensions :as hx]])
(:import [java.sql DatabaseMetaData ResultSet Types PreparedStatement]
[java.time OffsetDateTime OffsetTime]
[java.util Calendar TimeZone]))

(driver/register! :teradata, :parent :sql-jdbc)

Expand Down Expand Up @@ -249,6 +249,13 @@
[_ _ rs _ i]
(OffsetTime/parse (.getTime rs i)))

;; TODO: use metabase.driver.sql-jdbc.execute.legacy-impl instead of re-implementing everything here
(defmethod sql-jdbc.execute/set-parameter [:teradata OffsetDateTime]
[_ ^PreparedStatement ps ^Integer i t]
(let [cal (Calendar/getInstance (TimeZone/getTimeZone (t/zone-id t)))
t (t/sql-timestamp t)]
(.setTimestamp ps i t cal)))

(defn- run-query
"Run the query itself without setting the timezone connection parameter as this must not be changed on a Teradata connection.
Setting connection attributes like timezone would make subsequent queries behave unexpectedly."
Expand Down

0 comments on commit 8055d13

Please sign in to comment.