From 512ea075ffdbe104fac4c3328e76528d0309e71b Mon Sep 17 00:00:00 2001 From: mat02 Date: Mon, 19 Jul 2021 14:38:40 +0200 Subject: [PATCH] Fix for FB2.x - SUBSTRING function --- src/metabase/driver/firebird.clj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/metabase/driver/firebird.clj b/src/metabase/driver/firebird.clj index 88046c6..fb5abba 100644 --- a/src/metabase/driver/firebird.clj +++ b/src/metabase/driver/firebird.clj @@ -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] @@ -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)