Fixed bug reported by JTK related to the not-null sql-expression
authorRuss Tyndall <russ@acceleration.net>
Tue, 13 Dec 2011 14:13:25 +0000 (09:13 -0500)
committerNathan Bird <nathan@acceleration.net>
Wed, 4 Jan 2012 21:19:43 +0000 (16:19 -0500)
especially as used in conjunction with the is operator

Made null called with more than one argument throw an exception
instead of silently discarding all arguments past the first

ChangeLog
sql/operations.lisp
tests/test-syntax.lisp

index 9107ff22b4851987cb743f4a28d2a161fa547471..c49345b487680dce01820541df15583a4a99bead 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-01-04  Russ Tyndall  <russ@acceleration.net>
+       * sql/operations.lisp
+
+       Fixed bug reported by JTK related to the not-null sql-expression
+       especially as used in conjunction with the is operator.
+
+       Made null called with more than one argument throw an exception
+       instead of silently discarding all arguments past the first
+
 2012-01-04  Nathan Bird  <nathan@acceleration.net>
 
        * db-odbc/odbc-api.lisp (%sql-driver-connect): in the call to
index 7b558809a2503a2c65d4b459ece9a80a7b4ce575..37d751e0f90abc09189de627df483e1aab454119 100644 (file)
   (make-instance 'sql-query-modifier-exp
                  :modifier 'having :components rest))
 
-(defsql sql-null (:symbol "null") (&rest rest)
-  (if rest
+(defsql sql-null (:symbol "null") (&optional not-null-thing)
+  (if not-null-thing
       (make-instance 'sql-relational-exp :operator 'is
-                     :sub-expressions (list (car rest) nil))
+                     :sub-expressions (list not-null-thing nil))
       (make-instance 'sql-value-exp :components 'null)))
 
-(defsql sql-not-null (:symbol "not-null") ()
-  (make-instance 'sql-value-exp
-                 :components '|NOT NULL|))
+(defsql sql-not-null (:symbol "not-null") (&optional not-null-thing)
+  (if not-null-thing
+      (make-instance
+       'sql-relational-exp
+       :operator 'IS
+       :sub-expressions (list not-null-thing
+                              (sql-expression :string "NOT NULL")))
+      (sql-expression :string "NOT NULL")))
 
 (defsql sql-exists (:symbol "exists") (&rest rest)
   (make-instance 'sql-function-exp
index ed1f4817c604f3926a84304afe1b93e2928932dd..9bd666247ff860a86def758c4b4a6a528bd51364 100644 (file)
     (clsql:sql [not [null]])
   "(NOT (NULL))")
 
+(deftest :syntax/null/5
+    (clsql:sql [is [foo.bar] [null]])
+  "(FOO.BAR IS NULL)")
+
+(deftest :syntax/null/6
+    (clsql:sql [is [foo.bar] [not-null]])
+  "(FOO.BAR IS NOT NULL)")
+
+(deftest :syntax/null/7
+    (clsql:sql [not-null [foo.bar]])
+  "(FOO.BAR IS NOT NULL)")
+
 
 
 (deftest :syntax/relational/1