Commits

shantanuk  committed dbaf8f8

add deep-subquery support in IN clauses

  • Participants
  • Parent commits 8e185bd

Comments (0)

Files changed (1)

File src/main/clj/org/bituf/sqlrat/clause.clj

 ;; ========== WHERE clause functions ===========
 
 ;;;
+;; Convenience functions to join clauses by a delimiter
+
+(defn enclose-interpose
+  [sep-clause clause-1 & more]
+  (let [clauses (into [clause-1] more)]
+    (enclose (apply merge-clauses
+               (interpose sep-clause clauses)))))
+
+
+(defn AND
+  "Interpose clauses with \" AND \" and enclose the result"
+  ([clauses]
+    (if *assert-args* (assert (coll? clauses)))
+    (apply AND clauses))
+  ([clause-1 clause-2 & more]
+    (apply enclose-interpose " AND " clause-1 clause-2 more)))
+
+
+(defn OR
+  "Interpose clauses with \" OR \" and enclose the result"
+  ([clauses]
+    (if *assert-args* (assert (coll? clauses)))
+    (apply OR clauses))
+  ([clause-1 clause-2 & more]
+    (apply enclose-interpose " OR " clause-1 clause-2 more)))
+
+
+;;;
 ;; functions on 1 operand
 (defn is-null
   "Is null
     (let [v-vec (as-vector v-coll)
           _     (if (empty? v-vec)
                   (throw (IllegalArgumentException. "Value collection is empty")))
-          v-cnt (count v-vec)
-          qexpr (apply str (str-name k) kw "("
-                  (apply str
-                    (interpose ", " (take v-cnt (repeat \?)))) ")")]
-      (as-clause (into [qexpr] v-vec)))))
+          v-clauses (map #(if (clause? %) (enclose %) ; deep sub-query
+                            (as-value-clause %)) v-vec)]
+      (merge-clauses (as-clause k) kw
+        (apply enclose-interpose ", " v-clauses)))))
 
 
 (defn in?
     (map-to-clauses op2fn m)))
 
 
-;;;
-;; Convenience functions to join clauses by a delimiter
-
-(defn enclose-interpose
-  [sep-clause clause-1 clause-2 & more]
-  (let [clauses (into [clause-1 clause-2] more)]
-    (enclose (apply merge-clauses
-               (interpose sep-clause clauses)))))
-
-
-(defn AND
-  "Interpose clauses with \" AND \" and enclose the result"
-  ([clauses]
-    (if *assert-args* (assert (coll? clauses)))
-    (apply AND clauses))
-  ([clause-1 clause-2 & more]
-    (apply enclose-interpose " AND " clause-1 clause-2 more)))
-
-
-(defn OR
-  "Interpose clauses with \" OR \" and enclose the result"
-  ([clauses]
-    (if *assert-args* (assert (coll? clauses)))
-    (apply OR clauses))
-  ([clause-1 clause-2 & more]
-    (apply enclose-interpose " OR " clause-1 clause-2 more)))
-
-
 ;; === Comma separated names (for SELECT columns, GROUP BY, ORDER BY etc) ===
 
 (defn csnames