Merge branch 'develop' into multi-rs
This commit is contained in:
commit
cd3ddc3181
1 changed files with 9 additions and 16 deletions
|
|
@ -662,13 +662,12 @@
|
||||||
"Given a `Statement`, a SQL command, 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)
|
||||||
(when (:return-keys opts)
|
(try
|
||||||
(try
|
(.getGeneratedKeys stmt)
|
||||||
(.getGeneratedKeys stmt)
|
(catch Exception _))))
|
||||||
(catch Exception _)))))
|
|
||||||
|
|
||||||
(defn- reduce-stmt-sql
|
(defn- reduce-stmt-sql
|
||||||
"Execute the SQL command on the given `Statement`, attempt to get either
|
"Execute the SQL command on the given `Statement`, attempt to get either
|
||||||
|
|
@ -679,7 +678,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)
|
||||||
|
|
@ -699,7 +698,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, and fold that as a single element collection."
|
updated, and fold that as a single element collection."
|
||||||
[^Statement stmt sql n combinef reducef connectable opts]
|
[^Statement stmt sql n combinef reducef connectable 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)
|
||||||
chunk (fn [batch] (#'r/fjtask #(r/reduce reducef (combinef) batch)))
|
chunk (fn [batch] (#'r/fjtask #(r/reduce reducef (combinef) batch)))
|
||||||
realize (fn [row] (datafiable-row row connectable opts))]
|
realize (fn [row] (datafiable-row row connectable opts))]
|
||||||
|
|
@ -850,28 +849,22 @@
|
||||||
[{: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")
|
||||||
(reify
|
(reify
|
||||||
clojure.lang.IReduceInit
|
clojure.lang.IReduceInit
|
||||||
(reduce [_ f init]
|
(reduce [_ f init]
|
||||||
(reduce-stmt-sql this (first sql-params) f init
|
(reduce-stmt-sql this (first sql-params) f init opts))
|
||||||
(assoc opts :return-keys true)))
|
|
||||||
r/CollFold
|
r/CollFold
|
||||||
(coll-fold [_ n combinef reducef]
|
(coll-fold [_ n combinef reducef]
|
||||||
(fold-stmt-sql this (first sql-params) n combinef reducef
|
(fold-stmt-sql this (first sql-params) n combinef reducef
|
||||||
(.getConnection this)
|
(.getConnection this) opts))
|
||||||
(assoc opts :return-keys true)))
|
|
||||||
(toString [_] "`IReduceInit` from `plan` -- missing reduction?")))
|
(toString [_] "`IReduceInit` from `plan` -- missing reduction?")))
|
||||||
(-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)
|
(if-let [rs (stmt-sql->result-set this (first sql-params))]
|
||||||
(assoc opts :return-keys true))]
|
|
||||||
(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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue