From 6438c044866263d9e9b4da8d7c5b14c7da7c8f10 Mon Sep 17 00:00:00 2001 From: Justin Kramer Date: Thu, 16 Aug 2012 15:41:58 -0400 Subject: [PATCH] better null handling; normalize "not equal" variations as "<>" --- src/honeysql/format.clj | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index c7c9917..c047254 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -28,16 +28,29 @@ (def infix-fns #{"+" "-" "*" "/" "%" "mod" "|" "&" "^" - "is" "=" ">" ">=" "<" "<=" "<>" "!=" + ">" ">=" "<" "<=" "and" "or" "xor" "in" "not in" "like" "regexp"}) (def fn-aliases - {"not=" "!=" + {"is" "=" + "is-not" "<>" + "not=" "<>" + "!=" "<>" "not-in" "not in"}) (def fn-handlers - {"between" (fn [field upper lower] + {"=" (fn [f1 f2] + (cond + (= "NULL" f1) (str f2 " IS NULL") + (= "NULL" f2) (str f1 " IS NULL") + :else (str f1 " = " f2))) + "<>" (fn [f1 f2] + (cond + (= "NULL" f1) (str f2 " IS NOT NULL") + (= "NULL" f2) (str f1 " IS NOT NULL") + :else (str f1 " <> " f2))) + "between" (fn [field upper lower] (str field " BETWEEN " upper " AND " lower))}) (def clause-order