sql

All things SQL and JDBC...
2021-01-21T07:27:22.000200Z

I guess if I was a real clojure person, I should. I'm still pretty inexperienced. I have a java example that runs a query using jdbc. But it uses Oracle's DriverManager and sets some properties (System.setProperty(<k5 stuff>). Here's the java getting a connection object using a Properties props object with a url:

DriverManager.registerDriver(new OracleDriver());
		  Connection conn = DriverManager.getConnection(url, props);
I looked at next.jdbc: https://cljdoc.org/d/seancorfield/next.jdbc/1.1.613/api/next.jdbc.connection and I don't see anything similar for setting these properties. Looking at https://github.com/seancorfield/next-jdbc/blob/develop/src/next/jdbc/connection.clj it looks like the pieces are all there. It's just not obvious to me how to combine them properly. Let me know if you have any other breadcrumbs for me to follow or examples I can explore to research creating a connection using kerberos with clojure. The java examples are from here: https://www.rgagnon.com/javadetails/java-oracle-jdbc-connect-with-kerberos.html

John Conti 2021-01-21T19:20:35.003900Z

Hey there. Using java.jdbc 0.7.11 Noticed that the with-db-connection [conn db-spec {:auto-commit? false}] will not change the state of a connection if one is returned from db-find-connection:

(defmacro with-db-connection
  "Evaluates body in the context of an active connection to the database.
  (with-db-connection [con-db db-spec opts]
    ... con-db ...)"
  [binding &amp; body]
  `(let [db-spec# ~(second binding) opts# ~(or (second (rest binding)) {})]
     (if (db-find-connection db-spec#)
       (let [~(first binding) db-spec#]
         ~@body)
       (with-open [con# (get-connection db-spec# opts#)]
         (let [~(first binding) (add-connection db-spec# con#)]
           ~@body)))))

seancorfield 2021-01-21T20:38:07.005200Z

@john493 It would lead to some very hard to find bugs if you could pass a connection into a function and it mutated that connection without you knowing...

John Conti 2021-01-21T21:10:43.008700Z

My thought was that it needed the same kind of thing transaction* has. As it is now, if one says with-db-connection &lt;some valid db-spec&gt; {:auto-commit? false} is simply non-deterministic. If you pass a datasource, it works, a connection pool, it doesn’t. So the abstraction that says we are assigning characteristics to the resulting connection with the values in the map is misleading, because it doesn’t reliably do that. The other choice would be to remove the feature, than have it work for only some valid values of db-spec.

seancorfield 2021-01-21T21:35:22.009900Z

clojure.java.jdbc is effectively deprecated now so it almost certainly won't be changed (and it certainly won't have features removed). next.jdbc has superseded it.

seancorfield 2021-01-21T21:38:05.011100Z

(there is no "with connection" in next.jdbc -- you're expected to use with-open if you want to create a new connection and reuse it over several SQL operations)