On Wed, Nov 10, 2010 at 9:35 AM, Daniel Bell <dchristianb...@gmail.com> wrote:
>
> I'm a newb to both SQL and Clojure, and after reading this post
> ( 
> http://groups.google.com/group/clojure/browse_thread/thread/718fa1b725389639/4c4d7ed1492e082b?lnk=gst&q=sql+parameterized#4c4d7ed1492e082b
> ) I was curious as to exactly it means to parameterize a query. Is it
> a way to automatically insert arguments into the query, a way to
> destructure the results, or what?

Something like this:

(ns task.core
  (:use [clj-sql.core :as sql])
  (:use [task.db]))

(defn get-by-id
  ([id f]
    (sql/with-connection db
      (sql/with-query-results rows
        ["select * from task where key = ?" id]
        (f (first rows))))))

with-query-results takes three arguments: a variable to bind the
results to, a vector containing a SQL string and a sequence of
parameter values, and an expression to evaluate with the bound
results. In the SQL string, ? is a parameter placeholder and the
remaining items in the vector are the values that are substituted for
those placeholders.

Hope that helps?
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

-- 
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