add 3 new syntax tests for subqueries in SELECT, UPDATE,
[clsql.git] / tests / test-syntax.lisp
index 6cb1c0c1ce1d26df8a76f39b4ba234d18fd23673..c910448dcadd420016a9717a7aaf817cc533daa8 100644 (file)
@@ -14,7 +14,7 @@
 
 (in-package #:clsql-tests)
 
-#.(clsql:locally-enable-sql-reader-syntax)
+(clsql-sys:file-enable-sql-reader-syntax)
 
 
 (setq *rt-syntax*
     (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
                   [like (clsql:sql-expression :table table
                                              :attribute 'baz)
                         (clsql:sql table)])))
-  "(BETWEEN(THISTIME.BAR,(HIP * HOP),42) AND (THISTIME.BAZ LIKE 'THISTIME') AND BETWEEN(NEXTTIME.BAR,(HIP * HOP),43) AND (NEXTTIME.BAZ LIKE 'NEXTTIME') AND BETWEEN(SOMETIME.BAR,(HIP * HOP),44) AND (SOMETIME.BAZ LIKE 'SOMETIME') AND BETWEEN(NEVER.BAR,(HIP * HOP),45) AND (NEVER.BAZ LIKE 'NEVER'))")
-
-))
+  "(BETWEEN(THISTIME.BAR,(HIP * HOP),42) AND (THISTIME.BAZ LIKE 'THISTIME') AND BETWEEN(NEXTTIME.BAR,(HIP * HOP),43) AND (NEXTTIME.BAZ LIKE 'NEXTTIME') AND BETWEEN(SOMETIME.BAR,(HIP * HOP),44) AND (SOMETIME.BAZ LIKE 'SOMETIME') AND BETWEEN(NEVER.BAR,(HIP * HOP),45) AND (NEVER.BAZ LIKE 'NEVER'))"
+ )
+
+(deftest :syntax/subqueries/query
+ (clsql:sql
+  (clsql:sql-operation 'select [*]
+   :from [foo]
+   :where [in [id] [select [id] :from [bar]]]))
+ "SELECT * FROM FOO WHERE (ID IN (SELECT ID FROM BAR))")
+
+(deftest :syntax/subqueries/delete
+ (clsql:sql
+  (make-instance 'clsql-sys::sql-delete
+   :from [foo]
+   :where [in [id] [select [id] :from [bar]]]))
+ "DELETE FROM FOO WHERE (ID IN (SELECT ID FROM BAR))")
+
+(deftest :syntax/subqueries/update
+ (clsql:sql
+  (make-instance 'clsql-sys::sql-update
+   :attributes (list [id])
+   :values '(0)
+   :table [foo]
+   :where [in [id] [select [id] :from [bar]]]))
+ "UPDATE FOO SET ID = 0 WHERE (ID IN (SELECT ID FROM BAR))")
+
+ ))
 
 (defun test-output-sql/sql-ident-table ()
   (let ((tests `((,(make-instance 'sql-ident-table :name :foo) "FOO")
                     (test test-out expected-result)
                     "Test:~s didnt match ~S"
                     test-out expected-result))))
-
-#.(clsql:restore-sql-reader-syntax-state)