seancorfield / next-jdbc

A modern low-level Clojure wrapper for JDBC-based access to databases.
https://cljdoc.org/d/com.github.seancorfield/next.jdbc/
Eclipse Public License 1.0
760 stars 90 forks source link

Incorrect JDBC URL construction for H2 #174

Closed kelvinqian00 closed 3 years ago

kelvinqian00 commented 3 years ago

When constructing a JDBC URL for H2 using next.jdbc.connection/jdbc-url, the resulting URL uses the incorrect property separator, namely colons instead of ampersands. (H2 doc reference)

In addition, adding the :property-separator key to the param map adds an extraneous property-separator query param to the URL.

Code:

(next.jdbc.connection/jdbc-url
 {:dbtype "h2:mem"
  :dbname "test_db"
  :host "localhost"
  :port 9001
  :user "my_user"
  :password "swordfish"})

Expected:

=> "jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1;USER=my_user;PASSWORD=swordfish

Actual:

=> "jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1?user=my_user&password=swordfish

And this is the result when I add the kv-pair :property-separator ";" to the param map:

=> "jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1?user=my_user&password=swordfish;property-separator=;
seancorfield commented 3 years ago

Thanks! Fix on develop. I'll probably cut a new release over the weekend with this fix.

kelvinqian00 commented 3 years ago

Cool. However, I saw that you forgot to make :property-separator a keyword on this line: https://github.com/seancorfield/next-jdbc/blob/cc975f825dd9ee2993c43114b8f9454d00616feb/src/next/jdbc/connection.clj#L166

seancorfield commented 3 years ago

Ouch! Good catch, thank you! Glad I didn't get time to cut a new release with that bug still in it. Fixed on develop.

seancorfield commented 3 years ago

Version 1.2.709 is available with this fix.