X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=tests%2Ftest-syntax.lisp;h=01a76123d413021926d6e4cd199b56ef6fb0e765;hp=1127d3294c213970996d950b2cc9d3958e03db3e;hb=9fe9142259cca16202f35f66cbb35419752dd54d;hpb=90ce2284fab5f1daedb8aa6aba3008a5c3651e30 diff --git a/tests/test-syntax.lisp b/tests/test-syntax.lisp index 1127d32..01a7612 100644 --- a/tests/test-syntax.lisp +++ b/tests/test-syntax.lisp @@ -1,21 +1,20 @@ ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*- -;;;; ====================================================================== -;;;; File: test-syntax.lisp -;;;; Author: Marcus Pearce -;;;; Created: 30/03/2004 -;;;; Updated: $Id$ -;;;; ====================================================================== +;;;; ************************************************************************* +;;;; FILE IDENTIFICATION ;;;; -;;;; Description ========================================================== -;;;; ====================================================================== +;;;; Name: clsql.asd +;;;; Purpose: Tests for the CLSQL Symbolic SQL syntax. +;;;; Authors: Marcus Pearce and Kevin M. Rosenberg +;;;; Created: March 2004 ;;;; -;;;; Tests for the CLSQL Symbolic SQL syntax. -;;;; -;;;; ====================================================================== +;;;; CLSQL users are granted the rights to distribute and use this software +;;;; as governed by the terms of the Lisp Lesser GNU Public License +;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL. +;;;; ************************************************************************* (in-package #:clsql-tests) -#.(clsql:locally-enable-sql-reader-syntax) +(clsql-sys:file-enable-sql-reader-syntax) (setq *rt-syntax* @@ -191,6 +190,18 @@ (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 @@ -406,8 +417,49 @@ [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'))") - -)) - -#.(clsql:restore-sql-reader-syntax-state) + "(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))") + + )) + +(let ((tests '(((:foo) "FOO") + ((:foo-bar) "FOO_BAR") + (("foo") "\"foo\"") + (('|foo bar|) "\"foo bar\"") + ((:foo :table-alias :bar) "FOO BAR" ) + ((:foo_bar :table-alias :bar-bast) "FOO_BAR BAR_BAST") + (("foo" :table-alias "Bar") "\"foo\" \"Bar\"") + (('|foo bar| :table-alias :bast) "\"foo bar\" BAST")))) + + (push + `(deftest :syntax/sql-ident-table + (values ,@(mapcar + #'(lambda (args) + `(clsql:sql (make-instance 'clsql-sys:sql-ident-table + :name ,@args))) + (mapcar #'first tests))) + ,@(mapcar #'second tests)) + *rt-syntax*))