Browse files

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

… and .executeBatch otherwise.
  • Loading branch information...
1 parent 3dfff37 commit 9240d66c9124454187416861a0e2021952eb4f40 @seancorfield seancorfield committed Jun 27, 2011
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/main/clojure/clojure/java/jdbc/internal.clj
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 @@
(.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

0 comments on commit 9240d66

Please sign in to comment.