sql

All things SQL and JDBC...
bartuka 2020-03-31T11:51:23.096400Z

hi all! When I use sql/insert! and pass a map to it, I have to "rename" my map field and convert "-" to underscore, what would be the approach to make it be automatically converted?

dharrigan 2020-03-31T12:27:03.097Z

I use honeysql with next.jdbc, and the kebab to snakecase happens for me automatically

2020-03-31T13:50:28.097200Z

Oi

2020-03-31T13:51:00.097500Z

anyone implemented Readable column for tsrange in psql?

2020-03-31T13:55:34.098100Z

Hm, nevermind, that feels wrong to do, tbh. Any implementation would lose the idea of "range".

โœ”๏ธ 1
bartuka 2020-03-31T14:44:28.101200Z

@seancorfield yes I am using next.jdbc, lack that info. didn't know this keyword !! thanks

seancorfield 2020-03-31T14:46:58.102500Z

Read "All the Options" in the documentation -- may be other options you haven't seen yet that would help you

๐Ÿš€ 1
Saikyun 2020-03-31T16:32:51.103700Z

hello, I use next.jdbc -- is it possible to see the sql generated from e.g. sql/update! ? currently having a hard time debugging

Saikyun 2020-04-02T05:40:42.135200Z

@bfabry thanks for the tip, but I don't quite understand what you mean. either way, will try @seancorfield suggestion first ๐Ÿ™‚

2020-03-31T16:41:08.103800Z

reimplement this as a wrapper for your Executable/connectable but with logging? https://github.com/seancorfield/next-jdbc/blob/master/src/next/jdbc/protocols.clj#L33

2020-03-31T16:45:06.104100Z

aside: @seancorfield why's update! and execute-one! call the first parameter "connectable" but then call "Executable" protocol functions on it?

seancorfield 2020-03-31T16:55:28.105300Z

@saikyun You can call next.jdbc.sql.builder/for-update with the table key-map where-params opts arguments you are passing to update! (without the connectable one).

Saikyun 2020-04-02T05:39:49.135Z

aha, thanks. I'll try it out! ๐Ÿ™‚

seancorfield 2020-03-31T16:56:25.106Z

That will return the vector of SQL string and the list of parameter values that will be passed to JDBC (via the execute-one! function).

seancorfield 2020-03-31T17:00:44.106100Z

@bfabry Because "naming is hard" and it's a bit more descriptive of what's really happening: the Executable implementations need to obtain a Connection first before they execute the SQL. So you can pass a db-spec hash map, a JDBC string, a DataSource, or a Connection -- or a Statement, and only the latter is directly "executable".

๐Ÿ‘ 1
seancorfield 2020-03-31T17:02:46.106400Z

(but it's a very valid question -- initially the transact/`with-transaction` functions took a connectable but that was renamed to transactable via a community PR).

2020-03-31T18:43:22.114600Z

@seancorfield Hi Sean, using next-jdbc, I am querying a table containing a BLOB field, and am trying to get a column reader parsing that. I have almost got it working, but am a bit perplexed about the object type in the result set for the corresponding column. I the case of H2 database it seems to indeed implement java.sql.Blob, but when using the MySQL adapter the type seems to be a byte array [B. Have I screwed up somehow or is it just the way the MySQL adapter works?

seancorfield 2020-03-31T18:46:33.115900Z

@andreas179 Hard to tell without seeing code. I've never tried to use BLOB with MySQL so it's entirely possible it returns a byte array instead of java.sql.Blob -- have you looked at the MySQL docs for the connector?

seancorfield 2020-03-31T18:51:41.117800Z

Yeah, just tested it locally and it looks like the MySQL connector returns BLOB as byte[]

seancorfield 2020-03-31T18:54:02.120900Z

JDBC is notoriously non-portable once you get away from the basics... ยฏ\(ใƒ„)/ยฏ

seancorfield 2020-03-31T18:55:26.122800Z

I guess I'll update the CLOB & BLOB section of the Tips & Tricks documentation to mention that...

2020-03-31T18:55:58.123600Z

Looking in the docs (which I probably should have done before asking) reveals that the return value of GetColumnCalssName should return byte[] as you confirmed. However, the docs also states that the BLOB sql type always can be converted to java.sql.Blob among other. Oh well, now that I know whatโ€™s happening I can work around it. Thanks for a great library, docs are extensive and easy to follow as well! :)

seancorfield 2020-03-31T19:00:10.124500Z

Thanks. The one thing I will say about JDBC is that after maintaining Clojure wrappers around JDBC for nine years, I am still constantly learning "fascinating" new things about JDBC ๐Ÿ™‚

2020-03-31T19:05:21.126400Z

Awesome! At least weโ€™re getting something battle-tested, once oneโ€™ve worked around all quirks:sunglasses:

seancorfield 2020-03-31T21:14:48.128300Z

I can tell you that clojure.java.jdbc and next.jdbc are in extremely heavily daily usage where I work, with MySQL, and I get a lot of feedback from folks using PostgreSQL, so those are probably the two most battle-tested. But I test against a broad range of databases as a matter of course, including MS SQL Server, and I know there are folks using it with many other databases (including some I'd never heard of...).

๐Ÿ’ฏ 1