sql

Bingen Galartza Iparragirre 2025-02-13T08:48:16.155189Z

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.HikariProxyConnection

Bingen Galartza Iparragirre 2025-02-17T08:05:36.513759Z

OK, great! Thanks a lot!

Bingen Galartza Iparragirre 2025-02-14T08:15:08.791399Z

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.

seancorfield 2025-02-14T15:48:18.162959Z

Thanks. I'll dig into that some more. I suspect the unwrapping is losing the logging...🙁

👍 1
seancorfield 2025-02-14T20:44:54.940289Z

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...

seancorfield 2025-02-14T21:42:02.574519Z

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.

Bingen Galartza Iparragirre 2025-02-13T08:48:39.711499Z

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"}]

seancorfield 2025-02-13T17:31:53.712749Z

I've reopened that issue and will take a look later today.

seancorfield 2025-02-14T01:42:13.375479Z

@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?

Dos 2025-02-13T08:56:05.316879Z

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 ?

Dos 2025-02-13T09:47:59.503319Z

initial thought was something like this

seancorfield 2025-02-13T15:54:14.986719Z

Create a GH issue. I should provide a way to specify as-is properties when it isn't building URLs.

👍 1
Dos 2025-02-13T16:11:03.732619Z

thank you, Sean https://github.com/seancorfield/next-jdbc/issues/295

👍🏻 1
seancorfield 2025-02-13T18:20:45.437449Z

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...?

Dos 2025-02-14T04:44:56.574429Z

nice, thanks. it works

seancorfield 2025-02-14T04:45:54.064219Z

Excellent! I'll close that issue out then.

💪 1