<< Back to previous view

[CLJ-676] Calling seq on the resultset-seq of an empty ResultSet throws an exception Created: 16/Nov/10  Updated: 17/Dec/10  Resolved: 17/Dec/10

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.2
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Alex Miller Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None


The clojure.sql/resultset-seq function returns a seq over the JDBC ResultSet.

Expected: calling seq on an empty ResultSet should return nil
Actual: throws an error due to a closed ResultSet


(def db {:classname "oracle.jdbc.driver.OracleDriver"
         :subprotocol "oracle:thin"
         :subname "@detroit:1521:XE"
         :user "ted"
         :password "nugent"
         :schema "sweaty"})

(with-connection db
  (with-query-results res ["SELECT 1 FROM dual WHERE 0=1"]
    (seq res)))


java.sql.SQLRecoverableException: Closed Resultset: next
  [Thrown class java.lang.RuntimeException]

  0: clojure.lang.LazySeq.sval(LazySeq.java:47)
  1: clojure.lang.LazySeq.seq(LazySeq.java:56)
  2: clojure.lang.Cons.next(Cons.java:39)
  3: clojure.lang.RT.next(RT.java:560)
  4: clojure.core$next.invoke(core.clj:61)
  5: clojure.core$nthnext.invoke(core.clj:3399)
  6: clojure.core$print_sequential.invoke(core_print.clj:55)
  7: clojure.core$fn__4845.invoke(core_print.clj:138)
  8: clojure.lang.MultiFn.invoke(MultiFn.java:167)
  9: clojure.core$pr_on.invoke(core.clj:2812)
 10: clojure.core$pr.invoke(core.clj:2824)
 11: clojure.lang.AFn.applyToHelper(AFn.java:163)
 12: clojure.lang.RestFn.applyTo(RestFn.java:133)
 13: clojure.core$apply.invoke(core.clj:540)
 14: clojure.core$pr_str.doInvoke(core.clj:3700)
 15: clojure.lang.RestFn.invoke(RestFn.java:409)

Suggested workaround:

(with-connection db
  (with-query-results res ["SELECT 1 FROM dual WHERE 0=0"]
    (not (empty? res))))

Comment by Stuart Sierra [ 17/Dec/10 7:56 PM ]

This is not a Clojure issue. clojure.contrib.sql is part of the old clojure-contrib project, soon to be replaced.

Generated at Sat Jan 21 11:59:22 CST 2017 using JIRA 4.4#649-r158309.