commit 9e15c9aa894103468b616d573394a5a2042f9142 parent 94902930fe84af420c471f77df4da305ea1cf9aa Author: Tomas Hlavaty <tom@logand.com> Date: Tue, 2 Aug 2011 00:58:52 +0200 messy manual tests added Diffstat:
A | test.lisp | | | 172 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 172 insertions(+), 0 deletions(-)
diff --git a/test.lisp b/test.lisp @@ -0,0 +1,172 @@ +;;; cl-2sql Copyright (c) 2011 Tomas Hlavaty + +(in-package :2sql-tests) + +;; s-sql +(to-string + '(q:select ((q:+ field-1 100 @var) field-5) + (q:from (q:left-join my-table #+nil(my-table x) your-table (q:= x.field-2 your-table.field-1))) + (q:where (q:and field-1 field-2 (q:not field-1))))) + +'(:select ((:+ field-1 100 @var) field-5) + (:from (:left-join my-table #+nil(my-table x) your-table (:= x.field-2 your-table.field-1))) + (:where (:not-null a.field-3))) + +'(:select (:+ 'field-1 100) 'field-5 + :from (:as 'my-ta + :left-join 'your-table :on (:= 'x.field-2 'your-table.field-1) + :where (:not-null 'a.field-3))) + +(to-string '(q:select ((q:+ 1 1) (q:- 1 1)) (q:from :dual))) +(to-string '(q:select (:sysdate) (q:from :dual))) +(to-string '(q:select (user) (q:from :dual))) +(to-string '(q:select ((q:+ 1 1) x.sysdate) (q:from :dual))) +(to-string '(q:delete-from user)) +(to-string '(q:delete-from user (q:where (q:= name "John")))) + + +(defun optional (value) + (when value (list value))) + + + +(to-string '(q:drop-table user)) +(to-string '(q:drop-table user nil t)) +(to-string '(q:drop-table user t)) +(to-string '(q:drop-table user t t)) + +(to-string '(q:drop-view user nil)) +(to-string '(q:drop-view user t)) + +(to-string '(q:select ((q:cond ((q:zerop x) "yes") (t "no"))) (q:from :dual))) +(to-string '(q:select ((q:count (q:distinct user))) (q:from :dual))) + +;; clsql +(q:select [Researcher] :from '([TreeData] [SpeciesList]) + :where [and [= [TreeData SpeciesID] + [SpeciesList SpeciesID]] + [like [LocalName] "v%"]] + :distinct t :flatp t) + +(to-string + '(q:select ((q:distinct researcher)) + (q:from treedata specieslist) + (q:where (q:and (q:= treedata.speciesid specieslist.speciesid) + (q:like localname "v%"))))) + +(to-string + '(q:select (:*) + (q:from specieslist) + (q:where (q:between speciesid 6 9)))) + +(print-query "select * from SpeciesList + where (SpeciesID between 6 and 9)" + :titles (list-attributes "SpeciesList")) + + + +(to-string '(q:select (:*) (q:from x) (q:where (q:qvar hi)))) +-> "SELECT * FROM x_ WHERE :1", ((hi)), NIL + +(let ((v1 :v1) + (v2 :v2)) + (query + (q:select (:*) + (q:from x) + (q:where (q:and (q:= (q:qvar v1) (q:qchunk (+ 1 2))) + (q:= (q:qvar v2) (q:qchunk (+ 3 4)))))))) + +(let ((v1 "hello") + (v2 314159)) + (query + (q:select (:*) + (q:from x) + (q:where (q:= (q:qchunk (+ 1 2)) (q:qchunk "hello")))))) + + + + + + + +(2sql-lambda () + (q:select (:*) + (q:from x) + (q:where (q:= (q:qchunk (+ 1 2)) (q:qchunk (+ 3 4)))))) + +(define-function dasd () + (q:select (:*) + (q:from x) + (q:where (q:= (q:qchunk (+ 1 2)) (q:qchunk (+ 3 4)))))) + +(dasd) + + + +(define-function myfun (v1 v2) + (q:select (:*) + (q:from x) + (q:where (q:= (q:qvar v1) (q:qvar v2))))) + +(myfun 1 2) + +(define-function myfun (a1 a2) + (q:select (:*) + (q:from x) + (q:where (q:= a1 a2)))) + + + + + +(to-string + '(q:select (:*) + (q:from x) + (q:where (q:= (q:qvar v1) (q:qvar v2))))) + +(to-string + '(q:select (:*) + (q:from x) + (q:where (q:= (q:qchunk (+ 1 2)) (q:qchunk (+ 3 4)))))) + + + + +(let ((v1 "hello") + (v2 314159)) + (query (q:select (:*) + (q:from x) + (q:where (q:= (q:qvar v1) (q:qvar v2)))))) + + + + +(let ((v1 "hello") + (v2 314159)) + (query ;; macroexpand + (q:select (:*) + (q:from x) + (q:where (q:where (q:= (q:qvar v1) (q:qvar v2))))))) + +(let ((v1 "hello") + (v2 314159) + (v3 :v3) + (v4 :v4)) + (query ;; macroexpand + (q:union + (q:select (:*) + (q:from x) + (q:where + (q:and + (q:= (q:qvar v1) (q:qvar v2)) + (q:= (q:qvar v2) (q:qchunk (+ 1 2))) + (q:= (q:qvar v3) (q:qchunk "one")) + (q:= (q:qvar v4) (q:qchunk '(q:desc x)))))) + (q:select (:*) + (q:from x) + (q:where + (q:and + (q:= (q:qvar v1) (q:qvar v2)) + (q:= (q:qvar v2) (q:qchunk (+ 1 2))) + (q:= (q:qvar v3) (q:qchunk "one")) + (q:= (q:qvar v4) (q:qchunk '(q:desc x)))))))))