Clean up stmt-sql and :return-keys handling
This commit is contained in:
parent
067919a296
commit
a56c18d531
1 changed files with 11 additions and 7 deletions
|
|
@ -623,10 +623,10 @@
|
||||||
(f init {:next.jdbc/update-count (.getUpdateCount stmt)})))
|
(f init {:next.jdbc/update-count (.getUpdateCount stmt)})))
|
||||||
|
|
||||||
(defn- stmt-sql->result-set
|
(defn- stmt-sql->result-set
|
||||||
"Given a `Statement`, a SQL command, and options, execute it and return a
|
"Given a `Statement`, a SQL command, execute it and return a
|
||||||
`ResultSet` if possible. We always attempt to return keys."
|
`ResultSet` if possible. We always attempt to return keys."
|
||||||
^ResultSet
|
^ResultSet
|
||||||
[^Statement stmt ^String sql opts]
|
[^Statement stmt ^String sql]
|
||||||
(if (.execute stmt sql)
|
(if (.execute stmt sql)
|
||||||
(.getResultSet stmt)
|
(.getResultSet stmt)
|
||||||
(try
|
(try
|
||||||
|
|
@ -642,7 +642,7 @@
|
||||||
a hash map containing `:next.jdbc/update-count` and the number of rows
|
a hash map containing `:next.jdbc/update-count` and the number of rows
|
||||||
updated, with the supplied function and initial value applied."
|
updated, with the supplied function and initial value applied."
|
||||||
[^Statement stmt sql f init opts]
|
[^Statement stmt sql f init opts]
|
||||||
(if-let [rs (stmt-sql->result-set stmt sql opts)]
|
(if-let [rs (stmt-sql->result-set stmt sql)]
|
||||||
(let [rs-map (mapify-result-set rs opts)]
|
(let [rs-map (mapify-result-set rs opts)]
|
||||||
(loop [init' init]
|
(loop [init' init]
|
||||||
(if (.next rs)
|
(if (.next rs)
|
||||||
|
|
@ -747,14 +747,18 @@
|
||||||
(-execute-all [this _ opts]
|
(-execute-all [this _ opts]
|
||||||
(if (:multi-rs opts)
|
(if (:multi-rs opts)
|
||||||
(loop [go (.execute this) acc [] rsn 0]
|
(loop [go (.execute this) acc [] rsn 0]
|
||||||
(if-let [rs (stmt->result-set-update-count (.getConnection this) this go opts)]
|
(if-let [rs (stmt->result-set-update-count
|
||||||
|
(.getConnection this) this go (assoc opts :return-keys true))]
|
||||||
(recur (.getMoreResults this) (conj acc rs) (inc rsn))
|
(recur (.getMoreResults this) (conj acc rs) (inc rsn))
|
||||||
acc))
|
acc))
|
||||||
(if-let [rs (stmt->result-set this opts)]
|
(if-let [rs (stmt->result-set this (assoc opts :return-keys true))]
|
||||||
(datafiable-result-set rs (.getConnection this) opts)
|
(datafiable-result-set rs (.getConnection this) opts)
|
||||||
[{:next.jdbc/update-count (.getUpdateCount this)}])))
|
[{:next.jdbc/update-count (.getUpdateCount this)}])))
|
||||||
|
|
||||||
java.sql.Statement
|
java.sql.Statement
|
||||||
|
;; we can't tell if this Statement will return generated keys
|
||||||
|
;; but the stmt-sql routines pass a truthy value to at least
|
||||||
|
;; attempt it -- so we must explicitly pass it to the other calls
|
||||||
(-execute [this sql-params opts]
|
(-execute [this sql-params opts]
|
||||||
(assert (= 1 (count sql-params))
|
(assert (= 1 (count sql-params))
|
||||||
"Parameters cannot be provided when executing a non-prepared Statement")
|
"Parameters cannot be provided when executing a non-prepared Statement")
|
||||||
|
|
@ -765,7 +769,7 @@
|
||||||
(-execute-one [this sql-params opts]
|
(-execute-one [this sql-params opts]
|
||||||
(assert (= 1 (count sql-params))
|
(assert (= 1 (count sql-params))
|
||||||
"Parameters cannot be provided when executing a non-prepared Statement")
|
"Parameters cannot be provided when executing a non-prepared Statement")
|
||||||
(if-let [rs (stmt-sql->result-set this (first sql-params) opts)]
|
(if-let [rs (stmt-sql->result-set this (first sql-params))]
|
||||||
(let [builder-fn (get opts :builder-fn as-maps)
|
(let [builder-fn (get opts :builder-fn as-maps)
|
||||||
builder (builder-fn rs opts)]
|
builder (builder-fn rs opts)]
|
||||||
(when (.next rs)
|
(when (.next rs)
|
||||||
|
|
@ -781,7 +785,7 @@
|
||||||
(.getConnection this) this go (assoc opts :return-keys true))]
|
(.getConnection this) this go (assoc opts :return-keys true))]
|
||||||
(recur (.getMoreResults this) (conj acc rs) (inc rsn))
|
(recur (.getMoreResults this) (conj acc rs) (inc rsn))
|
||||||
acc))
|
acc))
|
||||||
(if-let [rs (stmt-sql->result-set this (first sql-params) opts)]
|
(if-let [rs (stmt-sql->result-set this (first sql-params))]
|
||||||
(datafiable-result-set rs (.getConnection this) opts)
|
(datafiable-result-set rs (.getConnection this) opts)
|
||||||
[{:next.jdbc/update-count (.getUpdateCount this)}])))
|
[{:next.jdbc/update-count (.getUpdateCount this)}])))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue