Skip to content
Snippets Groups Projects
Unverified Commit 4ed4c57d authored by Jeff Evans's avatar Jeff Evans Committed by GitHub
Browse files

Set program name on Oracle connections (#16968)

Update Oracle driver to set the v$session.program property on the connection, which appears in the PROGRAM column of the v$session table

Update tests accordingly
parent 3311b621
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
[honeysql.core :as hsql]
[honeysql.format :as hformat]
[java-time :as t]
[metabase.config :as config]
[metabase.driver :as driver]
[metabase.driver.common :as driver.common]
[metabase.driver.sql :as sql]
......@@ -81,15 +82,24 @@
(if sid (str "(SID=" sid ")") "")
(if service-name (str "(SERVICE_NAME=" service-name ")") ""))))
(def ^:private ^:const prog-name-property
"The connection property used by the Oracle JDBC Thin Driver to control the program name."
"v$session.program")
(defmethod sql-jdbc.conn/connection-details->spec :oracle
[_ {:keys [host port sid service-name]
:or {host "localhost", port 1521}
:as details}]
(assert (or sid service-name))
(let [spec {:classname "oracle.jdbc.OracleDriver", :subprotocol "oracle:thin"}
finish-fn (if (:ssl details) ssl-spec non-ssl-spec)]
finish-fn (if (:ssl details) ssl-spec non-ssl-spec)
;; the v$session.program value has a max length of 48 (see T4Connection), so we have to make it more terse than
;; the usual config/mb-version-and-process-identifier string and ensure we truncate to a length of 48
prog-nm (as-> (format "MB %s %s" (config/mb-version-info :tag) config/local-process-uuid) s
(subs s 0 (min 48 (count s))))]
(-> (merge spec details)
(dissoc :host :port :sid :service-name :ssl)
(assoc prog-name-property prog-nm)
(finish-fn host port sid service-name))))
(defmethod driver/can-connect? :oracle
......
......@@ -5,6 +5,7 @@
[clojure.test :refer :all]
[honeysql.core :as hsql]
[metabase.driver :as driver]
[metabase.driver.oracle :as oracle]
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
[metabase.driver.sql-jdbc.sync :as sql-jdbc.sync]
[metabase.driver.sql.query-processor :as sql.qp]
......@@ -58,9 +59,14 @@
:service-name "MyCoolService"
:sid "ORCL"
:ssl true}]]]
(is (= expected-spec
(sql-jdbc.conn/connection-details->spec :oracle details))
message)))
(let [actual-spec (sql-jdbc.conn/connection-details->spec :oracle details)
prog-prop (deref #'oracle/prog-name-property)]
(is (= (dissoc expected-spec prog-prop)
(dissoc actual-spec prog-prop))
message)
;; check our truncated Oracle version of the version/UUID string
;; in some test cases, the version info isn't set, to the string "null" is the value
(is (re-matches #"MB (?:null|v(?:.*)) [\-a-f0-9]*" (get actual-spec prog-prop))))))
(deftest require-sid-or-service-name-test
(testing "no SID and no Service Name should throw an exception"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment