korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.48k stars 222 forks source link

Oracle DB service name #350

Open pegerto opened 8 years ago

pegerto commented 8 years ago

Hello I am new with Clojure so try to understand the Korma code is hard for me, when I try to define a db connection to Oracle I need to pass the service name

@//host_name:port_number/service_name
(defn oracle
  "Create a database specification for an Oracle database. Opts should include keys
  for :user and :password. You can also optionally set host and port."
  [{:keys [host port]
    :or {host "localhost", port 1521}
    :as opts}]
  (merge {:subprotocol "oracle:thin"
          :subname     (str "@" host ":" port)}
         (dissoc opts :host :port)))

At the existing Ora configuration that I am running, without include the service name at the url I have the following issue

java.sql.SQLException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

I do not see any options at korma to specify this as part of the jdbc url, any idea how to overwrite the url?

Thanks

immoh commented 8 years ago

You can pass :subname instead of host and port:

(oracle {:subname "@//host_name:port_number/service_name"})
=>
{:classname "oracle.jdbc.driver.OracleDriver",
 :subprotocol "oracle:thin",
 :subname "@//host_name:port_number/service_name",
 :make-pool? true}

Pull request for adding support for service name option is welcome. 😄

ism-ssw commented 8 years ago

Actually there is another issue related to this. Oracle usually expects the connect strings to have the instance too ie there are three formats depending on the listener configuration:

@host_name:port_number:instance

or

@//host_name:port_number/service_name

or

@tns_name  (providing the location of the tnsnames,ora is set) 

Subtle difference as you can see but hard to think of best way to express in parameter terms

venantius commented 6 years ago

I'm going through old issues and trying to clean them up. Has this issue persisted?

If there hasn't been a response to this issue in 2 weeks, I'll close the ticket.