Skip to content

Commit

Permalink
changed Crossdata2 driver to fix problem with personalize queries (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
screspo-stratio authored May 8, 2019
1 parent 9f33d6c commit 25fc858
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 12 additions & 10 deletions src/metabase/driver/crossdata2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 25fc858

Please sign in to comment.