Fork me on GitHub
#sql
<
2018-10-28
>
kostafey18:10:00

There are 2 cases for oracle db connection URI: jdbc:oracle:thin:@<hostName>:<portNumber>:<sid>; (if you have sid) jdbc:oracle:thin:@<hostName>:<portNumber>/serviceName; (if you have oracle service name)

kostafey18:10:01

The current clojure.jdbc implementation creates the second format, with "/" char.

kostafey18:10:38

E.g. (def my-oracle-db {:dbtype "oracle" :dbname "dbname"... creates URI jdbc:oracle:thin:@host:port/dbname

kostafey18:10:11

But this can't work with outdated SID connections.

kostafey18:10:04

Could I ask to add the check for a "sid" string, so if I write (def my-oracle-db {:dbtype "oracle" :dbname "sid:dbname"... I'll receive the following URI: jdbc:oracle:thin:@host:port:dbname

kostafey18:10:18

it's a java.jdbc\src\main\clojure\clojure\java\jdbc.clj:384 db-sep (if (= "sqlserver" subprotocol) ";DATABASENAME=" "/")

kostafey19:10:29

Here is a probable solution: db-sep (if (= "sqlserver" subprotocol) ";DATABASENAME=" "/") url (cond (= "h2:mem" dbtype) (str "jdbc:" subprotocol ":" dbname ";DB_CLOSE_DELAY=-1") (#{"derby" "h2" "hsqldb" "sqlite"} subprotocol) (str "jdbc:" subprotocol ":" dbname) + (= "oracle" dbtype) + (str "jdbc:" subprotocol ":" + (host-prefixes subprotocol "//") + host + (when port (str ":" port)) + (if (= (.indexOf (str dbname) "sid:") 0) + (str ":" (str/replace dbname #"sid:" "")) + (str "/" dbname))) :else (str "jdbc:" subprotocol ":" (host-prefixes subprotocol "//") host (when port (str ":" port)) db-sep dbname))

seancorfield19:10:44

@kostafey Can you open a JIRA ticket with some details so I don't forget?

seancorfield19:10:52

Here's the URL to save you digging around https://dev.clojure.org/jira/browse/JDBC

kostafey19:10:48

Unfortunately, I can't find how to format code in this Jira.

seancorfield19:10:02

Thanks. I'll try to get a patch release out with that some time this week.

kostafey19:10:33

👍 Thank you!

seancorfield19:10:27

It'll be better to modify this line to deal with the db-sep value

db-sep (if (= "sqlserver" subprotocol) ";DATABASENAME=" "/")

seancorfield19:10:06

Also, I think I'd rather introduce a pseudo-subprotocol, oracle:sid, to handle this case.

seancorfield19:10:18

But I'll give that some thought.

seancorfield19:10:25

I don't really like the dbname having a "magic" prefix that goes away when the JDBC URL is constructed.

kostafey19:10:40

That's true. All solutions have their own disadvantages.

kostafey19:10:26

I think it's also possible to use ":" separator for all Oracle databases.

kostafey19:10:25

Since it works with both new and old-style connections. But probably someday later it will become deprecated.

seancorfield20:10:26

OK, fix for that pushed to GitHub. If you're using clj/`deps.edn` you can try it out via the latest git SHA...