I'm experiencing https://github.com/seancorfield/next-jdbc/issues/181 in the latest version of next.jdbc when combining with-options with with-logging. If I use one of them it works OK, but when using both I get the following error:
Execution error (IllegalArgumentException) at next.jdbc.protocols/eval41229$fn$G (protocols.clj:14).
No implementation of method: :get-datasource of protocol: #'next.jdbc.protocols/Sourceable found for class: com.zaxxer.hikari.pool.HikariProxyConnectionOK, great! Thanks a lot!
Thanks! The exception is gone, and the values are inserted, but I think the logging is not working? In the above snippet the first two are not printing anything, but the third does.
Thanks. I'll dig into that some more. I suspect the unwrapping is losing the logging...🙁
Looking at the code paths, there's no way to make the wrapped (options or logging) connectable work for execute-batch! without extensive changes I suspect.
I don't think those have ever worked with execute-batch! because, internally, it assumes a raw Connection can be passed to prepare -- if you pass a wrapped Connection (rather than, say, a wrapped DataSource); and on the non-`Connection` path, it uses get-connection and loses any wrapping anyway.
I'll keep poking at it but it's much harder to address than it looks...
OK, I relaxed the signature for prepare (to support a connectable, not just a Connection) and now execute-batch! can respect a logging-wrapped Connection (and does the pre-logging -- there is no post-logging in prepare). However, if you wrap a DataSource instead, the internal unwrapping will lose the logging (and default options). That's the nature of execute-batch!, I'm afraid.
Since with-transaction produces an (unwrapped) Connection object, and your code then wraps that, I think this round of changes will get your logging working.
SQL:
create table foo (a text);
Clojure:
(require '[next.jdbc :as jdbc])
(require '[next.jdbc.connection :as conn])
(def ds (conn/->pool com.zaxxer.hikari.HikariDataSource
{:jdbcUrl "jdbc:"}))
(jdbc/with-transaction [tx dso]
(let [ds (jdbc/with-options (jdbc/with-logging tx prn prn) {})]
(next.jdbc/execute-batch! ds "INSERT INTO foo(a) VALUES(?)" [["a"]] {})))
Execution error (IllegalArgumentException) at next.jdbc.protocols/eval41229$fn$G (protocols.clj:14).
No implementation of method: :get-datasource of protocol: #'next.jdbc.protocols/Sourceable found for class: com.zaxxer.hikari.pool.HikariProxyConnection
(jdbc/with-transaction [tx ds]
(let [ds (jdbc/with-logging (jdbc/with-options tx {}) prn prn)]
(next.jdbc.sql/insert-multi! ds :foo [:a] [["kaixo"]] {:batch true})))
Execution error (IllegalArgumentException) at next.jdbc.protocols/eval41229$fn$G (protocols.clj:14).
No implementation of method: :get-datasource of protocol: #'next.jdbc.protocols/Sourceable found for class: com.zaxxer.hikari.pool.HikariProxyConnection
(jdbc/with-transaction [tx ds]
(let [ds (jdbc/with-logging (jdbc/with-options tx {}) prn prn)]
(next.jdbc.sql/insert-multi! ds :foo [:a] [["kaixo"]] {:batch false})))
[#:foo{:a "kaixo"}] I've reopened that issue and will take a look later today.
@bingen.galartza There's a new 1.3.999-SNAPSHOT (or you can use git deps) that I believe will fix this. Could you test against that and let me know please?
Hello!
Here is https://docs.snowflake.com/en/developer-guide/jdbc/jdbc-configure#privatekey-property-in-connection-properties how to pass privateKey prop in conn props (yes, they use .put)
public static void main(String[] args)
throws Exception
{
String url = "jdbc:snowflake://.snowflakecomputing.com";
Properties prop = new Properties();
prop.put("user", "");
prop.put("privateKey", PrivateKeyReader.get(PRIVATE_KEY_FILE));
prop.put("db", "");
prop.put("schema", "");
prop.put("warehouse", "");
prop.put("role", "");
Connection conn = DriverManager.getConnection(url, prop);
Statement stat = conn.createStatement();
ResultSet res = stat.executeQuery("select 1");
res.next();
System.out.println(res.getString(1));
conn.close();
}
what is the best way to avoid https://github.com/seancorfield/next-jdbc/blob/develop/src/next/jdbc/connection.clj#L379 ?initial thought was something like this
Create a GH issue. I should provide a way to specify as-is properties when it isn't building URLs.
thank you, Sean https://github.com/seancorfield/next-jdbc/issues/295
I think what I'll do here is add a special property -- something like :next.jdbc/as-is-properties -- which can be a sequence of keywords whose property value should be .put as an Object instead of .setProperty'd as a String. I need to give it a bit more thought but if folks have feedback on such an idea...?
nice, thanks. it works
Excellent! I'll close that issue out then.