sql

All things SQL and JDBC...
strsnd 2020-07-31T18:22:33.354Z

@seancorfield For my use case it would be very helpful to allow to call get-connection with username and password in next-jdbc. I would like to propose a patch but am unsure if you would prefer to have username and pw as part of opts or as new arities of get-connection.

seancorfield 2020-07-31T18:26:33.354700Z

@hannes948 Is there a reason for you to not provide :user and :password as part of the hash map passed to get-datasource?

strsnd 2020-07-31T18:27:53.356Z

@seancorfield Sure, that's possible. But I am using different users with the same datasource and thought this approach would be cleaner and could help others as well.

seancorfield 2020-07-31T18:29:04.356900Z

The DataSource object supports (.getConnection ds username password) so you could get your connections that way.

seancorfield 2020-07-31T18:29:37.357600Z

(and that's true of the reified DataSource that get-datasource produces from a hash map or URL)

strsnd 2020-07-31T18:31:21.359400Z

Oh yeah. I was already using get-connection. I see, my patch would just be aesthetics then. 😉

seancorfield 2020-07-31T18:31:28.359700Z

I understand that's not as convenient so I'll have a think about it. Feel free to create an issue on GitHub.

strsnd 2020-07-31T18:32:06.360300Z

I will. If you come to a conclusion I am happy to help and provide a patch for that.

seancorfield 2020-07-31T18:34:21.361400Z

If you use a connection pooled datasource, aren't you restricted to a single user/password (since you have to provide that to c3p0 or HikariCP)? Or do those support connection-level user/password settings?

seancorfield 2020-07-31T18:38:51.364700Z

Given that I can't change the Connectable protocol without (potentially) breaking existing code, I'd want to pass :user / :password via the opts there (even if next.jdbc/get-connection was updated to have extra arities, it would resolve to (p/get-connection spec opts) under the hood), so then I think the only change would be this line in the private make-connection function would need to check for those keys in the opts:

(let [^Connection connection (.getConnection datasource)]
would become something like
(let [^Connection connection (if (and (:user opts) (:password opts)) (.getConnection datasource (:user opts) (:password opts)) (.getConnection datasource))]
^ @hannes948 Thoughts?

strsnd 2020-07-31T18:39:52.365800Z

@seancorfield hikari will throw an Unsupported SQL Exception, c3p0 has different pools for username+password

strsnd 2020-07-31T18:40:39.366600Z

The simple PostgreSQL Pool will just open a non-pooled Connection in this case.

seancorfield 2020-07-31T18:41:17.367100Z

(for the reified DataSource, that arity .getConnection only folds the username and password back into the etc hash map under the hood when calling DriverManager/getConnection anyway)

strsnd 2020-07-31T18:43:58.368900Z

I am fine with your proposal above, but my first attempt was to add new arities to the functions. We would go from spec and spec opts to spec user pass and spec user pass opts. I am not very experienced with java/clojure backwards "ABI" compatibility, but this change could break external users of the protocols, right?

seancorfield 2020-07-31T18:44:25.369400Z

Right. I'm not changing the arities in the protocol.

strsnd 2020-07-31T18:45:26.370900Z

I was writing a bit lengthy github issue talking about exactly this but do we want to continue here and I just submit a basic feature request?

seancorfield 2020-07-31T18:46:17.371800Z

I'm open to changing the arities in the top-level wrapper (`next.jdbc/get-connection`) but it would just assoc those into opts and pass that down. I'm just not sure of the value of that, given the narrowness of the use case (either unpooled connection or just c3p0, based on your comments above).

strsnd 2020-07-31T18:47:09.372300Z

Right, I would also be totally fine with leaving everything as is.

seancorfield 2020-07-31T18:51:46.373100Z

The change is pretty minor so I might as well go ahead and make it anyway at that level.

strsnd 2020-07-31T18:53:13.374200Z

I would welcome that! It allows me to continue to use the other options as well that get-connection provides and not having to fall back to a custom wrapper.

seancorfield 2020-07-31T18:57:35.375Z

@hannes948 Fixed on develop. Let me know how that works for you. I'll probably cut a new next.jdbc release this weekend if you need a published version on clojars?

strsnd 2020-07-31T18:58:15.375500Z

@hannes948 awesome, I can quickly pull it in and give it a test. Will report back in few minutes.

strsnd 2020-07-31T18:58:47.376200Z

There is no need to hurry with a release because of me.

seancorfield 2020-07-31T18:59:36.376900Z

There's already the execute-batch! enhancement pending a release so I was planning an update soon anyway.

strsnd 2020-07-31T19:11:18.377500Z

@seancorfield Tested and works. Thanks a lot!

1
2020-07-31T19:45:24.378200Z

having mixed auth in one pool sounds like a security problem

seancorfield 2020-07-31T19:55:06.379700Z

I remember reading that c3p0 supported that and thinking "Hmm, I wonder why anyone would do that?" 🙂

strsnd 2020-07-31T21:17:32.380700Z

@noisesmith they are distinct pools in c3p0, they are hashed by user+pw, the other pools that don't support it just throw an exception

strsnd 2020-07-31T21:18:26.381300Z

I try to use a ro user most of the time and just for some actions need to elevate

seancorfield 2020-07-31T21:30:58.382300Z

@hannes948 I can understand that. We have separate datasources for r/o vs r/w so it's usually very clear in our code which one is being used where.