Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #JDBC-10 by using .executeUpdate when attempting to return-keys…

… and .executeBatch otherwise.
  • Loading branch information...
commit 9240d66c9124454187416861a0e2021952eb4f40 1 parent 3dfff37
@seancorfield seancorfield authored
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/main/clojure/clojure/java/jdbc/internal.clj
View
10 src/main/clojure/clojure/java/jdbc/internal.clj
@@ -209,7 +209,9 @@
(defn do-prepared*
"Executes an (optionally parameterized) SQL prepared statement on the
open database connection. Each param-group is a seq of values for all of
- the parameters."
+ the parameters.
+ If return-keys, return the generated keys for the (single) update/insert.
+ else return a seq of update counts (one count for each param-group)."
[return-keys sql & param-groups]
(with-open [stmt (if return-keys
(.prepareStatement (connection*) sql java.sql.Statement/RETURN_GENERATED_KEYS)
@@ -222,8 +224,10 @@
param-group))
(.addBatch stmt))
(transaction* (fn []
- (let [rs (seq (.executeBatch stmt))]
- (if return-keys (first (resultset-seq* (.getGeneratedKeys stmt))) rs))))))
+ (if return-keys
+ (do (.executeUpdate stmt)
+ (first (resultset-seq* (.getGeneratedKeys stmt))))
+ (seq (.executeBatch stmt)))))))
(defn with-query-results*
"Executes a query, then evaluates func passing in a seq of the results as
Please sign in to comment.
Something went wrong with that request. Please try again.