sql

All things SQL and JDBC...
Mitch 2020-03-18T13:26:36.223700Z

What is the preferred way to keep your sql statements organized with jbdc.next?

Mitch 2020-03-18T13:27:42.225Z

I enjoyed using conman and keeping my sql in a .sql file with the previous iteration of the library, but it doesn't look like conman supports jdbc.next

Mitch 2020-03-18T13:30:29.225600Z

nevermind, looks like it is right in the docs: https://github.com/seancorfield/next-jdbc/blob/4d7940a5d346f9caa01d77aaf4f32bcbd61ce65d/doc/friendly-sql-functions.md

orestis 2020-03-18T14:02:13.226Z

HugSQL?

πŸ‘ 2
seancorfield 2020-03-18T18:51:41.227400Z

I'll give a :thumbsup::skin-tone-2: to HugSQL as it has built-in support for next.jdbc -- and it's also documented as part of the next.jdbc documentation https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT/doc/getting-started/friendly-sql-functions#hugsql-quick-start

πŸ˜„ 1
mbarillier 2020-03-18T19:28:09.228900Z

hi -- does anyone have a working example of a db-spec that connects to ms sql server? I'm on a linux box trying to connect using clojure.java.jdbc and keep getting authentication failures. I've tried setting :user to "DOMAIN\\username" and just "username", as well as something simillar in :subname. what's the syntax for using domain AD authentication in jdbc?

seancorfield 2020-03-18T19:43:35.229200Z

This is how next.jdbc connects to MS SQL Server: https://github.com/seancorfield/next-jdbc/blob/master/test/next/jdbc/test_fixtures.clj#L38-L42

seancorfield 2020-03-18T19:45:41.230700Z

^ @mbarillier Use the :dbtype/`:dbname` approach instead of trying to construct things with :subname etc.

seancorfield 2020-03-18T19:48:39.232900Z

next.jdbc assumes default host/port locally, clojure.java.jdbc uses :host/`:port` because that's an artifact of the different ways I test those two libraries (with clojure.java.jdbc I used a SQL Server Express instance running on an old Windows XP VM on my Mac; with next.jdbc I used Microsoft's official SQL Server Docker image based on Linux and exposed the host/port as 127.0.0.1:1433

seancorfield 2020-03-18T19:49:22.233500Z

Not sure how you'd do AD authentication if that's different from regular user/password.

mbarillier 2020-03-18T19:51:12.234300Z

@seancorfield lol ... neither do I πŸ™‚

seancorfield 2020-03-18T19:54:57.235300Z

The alternative is to construct the full JDBC URL yourself, based on whatever information you can find out there for how to connect via AD auth to SQL Server, and give that to c.j.j (or next.jdbc).

dpsutton 2020-03-18T20:12:06.236Z

AD is integrated security and based on the current logged in user right?

dpsutton 2020-03-18T20:12:45.236500Z

Been a while since my .NET days

mbarillier 2020-03-18T20:50:21.236900Z

@dpsutton yes, there's an integratedSecurity=true option on the connect string, but works only on windows (I'm on linux)

dpsutton 2020-03-18T20:52:42.238200Z

Can you try using that connection string from a more traditional client? I’m guessing it won’t work from Linux at all

mbarillier 2020-03-18T21:00:31.241100Z

I got it to work using a connect string, something like: "jdbc:<sqlserver://HOST>:PORT;databaseName=DBNAME;user=ID;password=PWD". I don't understand how this active directory authentication works, but apparently the service account I used doesn't require a domain, but mine does. microsoft products are a nightmare (IMHO).

seancorfield 2020-03-18T21:14:51.242400Z

@mbarillier Given that URL works, I would expect a db-spec map of

{:dbtype "sqlserver"
 :dbname "DBNAME"
 :host "HOST"
 :port PORT
 :user "ID"
 :password "PWD"}
to work also

seancorfield 2020-03-18T21:15:20.243Z

(and that should work with both clojure.java.jdbc or next.jdbc -- and I'd encourage you to use the latter if you are just getting started)