On Fri, Jan 25, 2013 at 2:27 PM, Jonathon McKitrick
<jmckitr...@gmail.com> wrote:
> (defn get-by-ids-test
>   [ids]
>   (let [qs (string/join "," (repeat (count ids) "?"))
>         sql (str "select * from survey where survey_id in (" qs ")")]
>     (println "SQL " sql)
>     (println "ids" ids)
>     (sql/with-connection (get-db-spec)
>       (sql/with-query-results results
>         [sql ids]

Try:
    (into [sql] ids)

>         (into [] results)))))

The vector should be a SQL string followed by the various parameter
values. You have a SQL string followed by a single item - a sequence
of parameter values.

In the next version of java.jdbc (currently 0.2.4-SNAPSHOT but it will
become 0.3.0), you'll be able to simplify your code to this:

    (sql/query (get-db-spec) (into [sql] ids))

and get back a fully realized sequence of maps. If you want a vector instead:

    (sql/query (get-db-spec) (into [sql] ids) :resultset-fn vec)

;; the current code has :result-set-fn but that will change since it's
not consistent with the resultset type or resultset-seq function!

Since the question of `where in` comes in fairly often, I will
probably extend the minimal DSL that 0.3.0 will add (in a separate
optional ns) to support that, e.g.,

    (sql/query (get-db-spec) (dsl/select * :survey (dsl/where
{:survey_id ids})))

perhaps with dsl/in to make it read better... although I expect you'd
:refer in the symbols you needed to get this:

    (query (get-db-spec) (select * :survey (where {:survey_id (in ids)})))

The current thinking is to keep the DSL deliberately small (and
optional) so that other folks can develop richer DSLs that are
compatible with java.jdbc directly (i.e., this is explicitly not
intended to "compete" with Korma - just to make Korma's job easier).
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Reply via email to