Skip to content

Commit

Permalink
Fix for FB2.x - SUBSTRING function
Browse files Browse the repository at this point in the history
  • Loading branch information
mat02 committed Jul 19, 2021
1 parent 90e797b commit 512ea07
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/metabase/driver/firebird.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[string :as str]]
[clojure.java.jdbc :as jdbc]
[honeysql.core :as hsql]
[honeysql.format :as hformat]
[java-time :as t]
[metabase.driver :as driver]
[metabase.driver.common :as driver.common]
Expand Down Expand Up @@ -156,6 +157,20 @@
;; Firebird 2.x doesn't support TRUE/FALSE, replacing them with 1 and 0
(defmethod sql.qp/->honeysql [:firebird Boolean] [_ bool] (if bool 1 0))

;; Firebird 2.x doesn't support SUBSTRING arugments seperated by commas, but uses FROM and FOR keywords
(defmethod sql.qp/->honeysql [:firebird :substring]
[driver [_ arg start length]]
(let [col-name (hformat/to-sql (sql.qp/->honeysql driver arg))]
(if length
(reify
hformat/ToSql
(to-sql [_]
(str "substring(" col-name " FROM " start " FOR " length ")")))
(reify
hformat/ToSql
(to-sql [_]
(str "substring(" col-name " FROM " start ")"))))))

(defmethod sql.qp/add-interval-honeysql-form :firebird [driver hsql-form amount unit]
(if (= unit :quarter)
(recur driver hsql-form (hx/* amount 3) :month)
Expand Down

0 comments on commit 512ea07

Please sign in to comment.