diff --git a/src/jdbc.clj b/src/jdbc.clj index 546dee3..6994867 100644 --- a/src/jdbc.clj +++ b/src/jdbc.clj @@ -281,7 +281,7 @@ For more details, see documentation." (if (is-prepared-statement? sql) (execute-statement! conn sql param-groups) (let [connection (:connection conn)] - (with-open [stmt (.prepareStatement connection sql)] + (with-open [stmt (.prepareStatement connection sql java.sql.Statement/RETURN_GENERATED_KEYS)] (execute-statement! conn stmt param-groups))))) (defn make-prepared-statement @@ -311,7 +311,8 @@ For more details, see documentation." (holdability constants/resultset-options)) (.prepareStatement connection sql (result-type constants/resultset-options) - (result-concurency constants/resultset-options)))] + (result-concurency constants/resultset-options))) + stmt (.prepareStatement connection sql (into-array String ["id"]))] ;; Lazy resultset works with database cursors ant them can not be used ;; without one transaction (when (and (not (:in-transaction conn)) lazy) diff --git a/test/jdbc_test.clj b/test/jdbc_test.clj index fb6da97..970d097 100644 --- a/test/jdbc_test.clj +++ b/test/jdbc_test.clj @@ -30,6 +30,23 @@ :host "localhost" :read-only true}) + +(deftest db-extra-returning-keys + (testing "Testing basic returning keys" + (with-connection [conn pg-dbspec] + (try + (execute! conn "DROP TABLE IF EXISTS foo_retkeys;") + (execute! conn "CREATE TABLE foo_retkeys (id int primary key, num integer);") + (let [sql (str "INSERT INTO foo_retkeys (id, num) VALUES (?, ?)") + stmt (make-prepared-statement conn sql)] + (let [res (execute-prepared! conn stmt [2, 0] [3, 0])] + (println 111, (result-set->vector conn (.getGeneratedKeys stmt) {})) + (println 222, res))) + (catch java.sql.BatchUpdateException e + (.printStackTrace e) + (.printStackTrace (.getNextException e)))))) +) + (deftest db-specs (testing "Create connection with distinct dbspec" (let [c1 (make-connection h2-dbspec1)