Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additional connection string options for Oracle [Experimental] #4923

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/metabase/driver/generic_sql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@
(defn handle-additional-options
"If DETAILS contains an `:addtional-options` key, append those options to the connection string in CONNECTION-SPEC.
(Some drivers like MySQL provide this details field to allow special behavior where needed)."
{:arglists '([connection-spec details])}
[{connection-string :subname, :as connection-spec} {additional-options :additional-options, :as details}]
(-> (dissoc connection-spec :additional-options)
(assoc :subname (str connection-string (when (seq additional-options)
(str (if (str/includes? connection-string "?") "&" "?")
additional-options))))))
{:arglists '([connection-spec] [connection-spec details])}
;; single arity provided for cases when `connection-spec` is built by applying simple transformations to `details`
([connection-spec]
(handle-additional-options connection-spec connection-spec))
;; two-arity version provided for when `connection-spec` is being built up separately from `details` source
([{connection-string :subname, :as connection-spec} {additional-options :additional-options, :as details}]
(-> (dissoc connection-spec :additional-options)
(assoc :subname (str connection-string (when (seq additional-options)
(str (if (str/includes? connection-string "?") "&" "?")
additional-options)))))))


(defn escape-field-name
Expand Down
15 changes: 10 additions & 5 deletions src/metabase/driver/oracle.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@

(defn- connection-details->spec
"Create a database specification for an Oracle database. DETAILS should include keys
for `:user`, `:password`, and `:sid`. You can also optionally set `:host` and `:port`."
for `:user`, `:password`, and `:sid`. You can also optionally set `:host` and `:port`, and
supply `:addtional-options` that are appended to the end of the JDBC connection string."
[{:keys [host port sid]
:or {host "localhost", port 1521}
:as details}]
(merge {:subprotocol "oracle:thin"
:subname (str "@" host ":" port ":" sid)}
(dissoc details :host :port)))
(-> (merge {:subprotocol "oracle:thin"
:subname (str "@" host ":" port ":" sid)}
(dissoc details :host :port))
sql/handle-additional-options))

(defn- can-connect? [details]
(let [connection (connection-details->spec details)]
Expand Down Expand Up @@ -213,7 +215,10 @@
{:name "password"
:display-name "Database password"
:type :password
:placeholder "*******"}]))
:placeholder "*******"}
{:name "additional-options"
:display-name "Additional JDBC connection string options"
:placeholder "serviceName=myservicename"}]))
:execute-query (comp remove-rownum-column sqlqp/execute-query)})

sql/ISQLDriver
Expand Down
17 changes: 17 additions & 0 deletions test/metabase/driver/oracle_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(ns metabase.driver.oracle-test
"Tests for specific behavior of the Oracle driver."
(:require [expectations :refer :all]
[metabase.driver
[generic-sql :as sql]
oracle])
(:import metabase.driver.oracle.OracleDriver))

;; make sure we can set additional connection string options
(expect
{:subprotocol "oracle:thin"
:subname "@localhost:1521:ORCL?serviceName=myservicename"
:sid "ORCL"}
(sql/connection-details->spec (OracleDriver.) {:host "localhost"
:port 1521
:sid "ORCL"
:additional-options "serviceName=myservicename"}))
4 changes: 3 additions & 1 deletion test/metabase/driver/postgres_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
[query-processor-test :refer [rows]]
[sync-database :as sync-db]
[util :as u]]
[metabase.driver.generic-sql :as sql]
[metabase.driver
[generic-sql :as sql]
postgres]
[metabase.models
[database :refer [Database]]
[field :refer [Field]]
Expand Down