How to call next() on a resultset in clojure.contrib.sql? -


originally going ask why having problems calling (seq) on result set test emptiness, bit of research showed it's apparently because jdbc cursor hasn't moved anywhere. fine , dandy. there way call next() on resultset if don't know name? can bind symbol in clojure, haven't been able figure out how call method there.

edit: in case it's not clear, i'm referring java resultset method next(), not clojure (next)

edit#2 here's code snippet:

(defn user-exists? [email]   (with-connection db    (with-query-results res ["select guid users email=?" email]     (.next res)     (seq res)))) 

(thanks on .next, btw...haven't done java interop yet)

still, though, using (seq) throws nullpointerexception if query didn't return anything. i'm wondering if there's cleaner, idiomatic way this?

res bound clojure sequence based on resultset each item map of result record output column names keywords in keys. can't underlying actual resultset object.

typically don't call next @ all. idiomatic clojure, utilize vast library of functions operate on sequences (map, filter, reduce, etc) produce output. here might like:

(with-query-results res ["select guid users email=?" email]   (map :guid res)) 

which apply :guid function on res seqeuence , retrieve column value of guid in each record, returning new sequence of guids. wrap map in filter or whatever else needed.

in case, seq should want think abstraction leaking bit. when tried got java.sql.sqlrecoverableexception: closed resultset: next implies me resultset being closed in abstraction. however, found empty? worked ok use case.

(defn user-exists? [email]   (with-connection db    (with-query-results res ["select guid users email=?" email]     (.next res)     (not (empty? res))))) 

this seems bug in clojure.core/resultset-seq me , reported here clj-676.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -