diff options
author | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-05-14 12:31:50 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-05-14 12:31:50 +1000 |
commit | 1c5a0359f7b048ad01a25607661229e13b5a6be7 (patch) | |
tree | ab275c4e5deba1920a8cbbbaef559a04f608e864 | |
parent | 431b961d6bbb0008bdb4fce81ad2cf9d6ab0a287 (diff) |
Apparently I got the jdbc query syntax wrong. Corrected.
The parameters should be passed in the `rest` of the vector, not as a separate
seq. My bad.
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | src/clojure_sql/core.clj | 16 |
2 files changed, 11 insertions, 9 deletions
@@ -19,7 +19,7 @@ data to be inserted, updated and deleted. (-> (s/table :users) (s/project [:id :username]) deref) - ; => ["SELECT \"users\".\"id\", \"users\".\"username\" FROM \"users\"" ()] + ; => ["SELECT \"users\".\"id\", \"users\".\"username\" FROM \"users\""] (-> (s/table {:users :u}) (s/project [:id :username]) @@ -30,7 +30,7 @@ data to be inserted, updated and deleted. '(= :uid :pid)) (s/project [:username]) deref) - ; => ["SELECT \"u\".\"username\" FROM \"users\" AS \"u\" JOIN \"people\" AS \"p\" ON (\"u\".\"id\" = \"p\".\"id\") WHERE (\"p\".\"fname\" = ?)" ("Henry"))] + ; => ["SELECT \"u\".\"username\" FROM \"users\" AS \"u\" JOIN \"people\" AS \"p\" ON (\"u\".\"id\" = \"p\".\"id\") WHERE (\"p\".\"fname\" = ?)" "Henry")] ## License diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj index 319d281..e1dfb90 100644 --- a/src/clojure_sql/core.clj +++ b/src/clojure_sql/core.clj @@ -28,16 +28,18 @@ (def is-unary? (comp boolean '#{not})) (def is-predicate? (comp boolean '#{= < > <= >= is in})) -(defn c-return [val] [val nil]) +(defn c-return [val] [val]) (defn c-lift [f & orig-args] (fn [& c-args] - [(apply f (concat orig-args - (map first c-args))) - (apply concat (map second c-args))])) + (apply vector + (apply f (concat orig-args + (map first c-args))) + (apply concat (map rest c-args))))) (def c-str (c-lift str)) (def c-join (fn [sep args] - [(string/join sep (map first args)) - (apply concat (map second args))])) + (apply vector + (string/join sep (map first args)) + (apply concat (map rest args))))) (def c-add-parentheses (c-lift add-parentheses)) (defmulti compile-expression (fn [db _] db)) @@ -46,7 +48,7 @@ nil? (c-return "NULL") vector? (c-return (str (table-name db (first ex)) \. (field-name db (second ex)))) keyword? (c-return (field-name db ex)) - string? ["?" [ex]] ;;(sql-string db ex) + string? ["?" ex] ;;(sql-string db ex) symbol? (c-return (string/upper-case (name ex))) sequential? (-> (if (= (count ex) 2) (->> ex |