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
767 stars 90 forks source link

clojure.java.jdbc/next.jdbc insert-multi! #264

Closed dharrigan closed 11 months ago

dharrigan commented 11 months ago

Hi,

Related Issue #263

With clojure.java.jdbc, if an empty sequence is passed into insert-multi!, it appears to silently ignore the insert and do nothing. With next.jdbc, an error is returned:

(next.jdbc.sql/insert-multi! db table [])

Uncaught exception, not in assertion.
expected: nil
  actual: java.lang.AssertionError: Assert failed: column counts are not consistent across cols and rows
(apply = (count cols) (map count rows))
at next.jdbc.sql.builder$for_insert_multi.invokeStatic (builder.clj:147)
    next.jdbc.sql.builder$for_insert_multi.invoke (builder.clj:133)

Whilst I do believe next.jdbc is more correct, perhaps it might be worthwhile to mimic clojure.java.jdbc's behaviour for backwards compatibility? (I could always just do a (when (seq records) (insert-multi! db table records)) as a guard statement beforehand :-) )

Environment (please complete the following information):

Linux daffy 6.6.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 08 Nov 2023 16:05:38 +0000 x86_64 GNU/Linux

openjdk 21.0.1 2023-10-17 LTS
OpenJDK Runtime Environment Temurin-21.0.1+12 (build 21.0.1+12-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.1+12 (build 21.0.1+12-LTS, mixed mode, sharing)

Clojure 1.11.1 next.jdbc 1.3.894 com.mysql/mysql-connector-j 8.2.0

Do let me know if you require more information.

Thank you!

-=david=-