From 25fc858ee56b705c8fbbbf46443daf00c2f0668a Mon Sep 17 00:00:00 2001 From: screspo-stratio <48674019+screspo-stratio@users.noreply.github.com> Date: Wed, 8 May 2019 19:50:32 +0200 Subject: [PATCH] changed Crossdata2 driver to fix problem with personalize queries (#119) --- CHANGELOG.md | 4 ++++ src/metabase/driver/crossdata2.clj | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c8dc8d39d3c..e10b370a2f6b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.33.2 (upcoming) + +* [SS-5301] Personalize queries with filter returned error. Fixed in the Crossdata2 driver. + ## 0.33.1 (May 06, 2019) * [ROCK-56] Upgrade XD jdbc from 2.14.3 to 2.14.4 diff --git a/src/metabase/driver/crossdata2.clj b/src/metabase/driver/crossdata2.clj index a4c9bf1c8409c..1e445cd3c75ee 100644 --- a/src/metabase/driver/crossdata2.clj +++ b/src/metabase/driver/crossdata2.clj @@ -104,22 +104,24 @@ (defn execute-query "Process and run a native (raw SQL) QUERY." - [driver {:keys [database settings], query :native, :as outer-query}] - + [driver {:keys [database settings ], query :native, {sql :query, params :params} :native, :as outer-query}] (def query_with_nominal_user (assoc query :query (str "execute as " (get @api/*current-user* :first_name) " " (get query :query)))) (println "query modificada con usuario: " query_with_nominal_user) - (let [db-connection (sql/db->jdbc-connection-spec database)] - (let [query (assoc query :remark (qputil/query->remark outer-query))] - (qprocessor/do-with-try-catch - (fn [] - (if (true? (get-in database [:details :impersonate])) - (qprocessor/do-in-transaction db-connection (partial qprocessor/run-query-with-out-remark query_with_nominal_user)) - (qprocessor/do-in-transaction db-connection (partial qprocessor/run-query-with-out-remark query)))))))) - + (let [sql (str + (if (seq params) + (unprepare/unprepare (cons sql params)) + sql))] + (let [db-connection (sql/db->jdbc-connection-spec database)] + (let [query (assoc query :remark "", :query sql, :params nil)] + (qprocessor/do-with-try-catch + (fn [] + (if (true? (get-in database [:details :impersonate])) + (qprocessor/do-in-transaction db-connection (partial qprocessor/run-query-with-out-remark query_with_nominal_user)) + (qprocessor/do-in-transaction db-connection (partial qprocessor/run-query-with-out-remark query))))))))) (defn apply-order-by "Apply `order-by` clause to HONEYSQL-FORM. Default implementation of `apply-order-by` for SQL drivers."