X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=tests%2Ftest-fdml.lisp;h=56787a21d012bd3bebde380936f8bf31a2842b80;hb=d9b32644383f3c4087d0ecac10c645f38d17648d;hp=a4b8bb18ed2c016dc8b7c7762fa82d99359f0dfe;hpb=792574509621ab4ed0279db1483c5af1c78df93b;p=clsql.git diff --git a/tests/test-fdml.lisp b/tests/test-fdml.lisp index a4b8bb1..56787a2 100644 --- a/tests/test-fdml.lisp +++ b/tests/test-fdml.lisp @@ -154,6 +154,31 @@ 'float) t) +(deftest :fdml/query/5 + (clsql:query (clsql:sql [select [first-name] [sum [emplid]] :from [employee]] + [group-by [first-name]] [order-by [sum [emplid]]]) + :field-names nil :result-types nil) + (("Josef" "2") ("Leon" "3") ("Nikita" "4") ("Leonid" "5") ("Yuri" "6") + ("Konstantin" "7") ("Mikhail" "8") ("Boris" "9") ("Vladamir" "11"))) + +(deftest :fdml/query/6 + (clsql:query (clsql:sql [union [select [emplid] :from [employee]] + [select [groupid] :from [company]]]) + :field-names nil :result-types nil :flatp t) + ("1" "2" "3" "4" "5" "6" "7" "8" "9" "10")) + +(deftest :fdml/query/7 + (clsql:query (clsql:sql [intersect [select [emplid] :from [employee]] + [select [groupid] :from [company]]]) + :field-names nil :result-types nil :flatp t) + ("1")) + +(deftest :fdml/query/8 + (clsql:query (clsql:sql [except [select [emplid] :from [employee]] + [select [groupid] :from [company]]]) + :field-names nil :result-types nil :flatp t) + ("2" "3" "4" "5" "6" "7" "8" "9" "10")) + (deftest :fdml/execute-command/1 (values (clsql:table-exists-p [foo] :owner *test-database-user*) @@ -223,7 +248,7 @@ ("lenin@soviet.org")) (deftest :fdml/select/6 - (if (db-type-has-fancy-math? *test-database-underlying-type*) + (if (clsql-sys:db-type-has-fancy-math? *test-database-underlying-type*) (mapcar #'(lambda (s) (parse-integer s :junk-allowed t)) (clsql:select [function "trunc" [height]] :from [employee] :result-types nil @@ -313,11 +338,123 @@ :field-names nil) (("1" "Lenin"))) -;(deftest :fdml/select/11 -; (clsql:select [emplid] :from [employee] -; :where [= [emplid] [any [select [companyid] :from [company]]]] -; :flatp t) -; ("1")) +(deftest :fdml/select/19 + (clsql:select [emplid] :from [employee] :order-by [emplid] + :where [between [* [emplid] 10] [* 5 10] [* 10 10]] + :field-names nil :result-types nil :flatp t) + ("5" "6" "7" "8" "9" "10")) + +(deftest :fdml/select/20 + (clsql:select [emplid] :from [employee] :order-by [emplid] + :where [not [between [* [emplid] 10] [* 5 10] [* 10 10]]] + :field-names nil :result-types nil :flatp t) + ("1" "2" "3" "4")) + +(deftest :fdml/select/21 + (clsql:select [substr [first-name] 1 4] :from [employee] + :flatp t :order-by [emplid] :field-names nil) + ("Vlad" "Jose" "Leon" "Niki" "Leon" "Yuri" "Kons" "Mikh" "Bori" "Vlad")) + +(deftest :fdml/select/22 + (clsql:select [|| [first-name] " " [last-name]] :from [employee] + :flatp t :order-by [emplid] :field-names nil) + ("Vladamir Lenin" "Josef Stalin" "Leon Trotsky" "Nikita Kruschev" + "Leonid Brezhnev" "Yuri Andropov" "Konstantin Chernenko" "Mikhail Gorbachev" + "Boris Yeltsin" "Vladamir Putin")) + +(deftest :fdml/select/23 + (clsql:select [emplid] :from [employee] :where [in [emplid] '(1 2 3 4)] + :flatp t :order-by [emplid] :field-names nil + :result-types nil) + ("1" "2" "3" "4")) + +(deftest :fdml/select/24 + (clsql:select [distinct [first-name]] :from [employee] :flatp t + :order-by [first-name] :field-names nil :result-types nil) + ("Boris" "Josef" "Konstantin" "Leon" "Leonid" "Mikhail" "Nikita" "Vladamir" + "Yuri")) + +(deftest :fdml/select/25 + (clsql:select [first-name] :from "employee" :flatp t :distinct t + :field-names nil + :result-types nil + :order-by [first-name]) + ("Boris" "Josef" "Konstantin" "Leon" "Leonid" "Mikhail" "Nikita" "Vladamir" + "Yuri")) + +(deftest :fdml/select/26 + (clsql:select ["table" first-name] ["table" last-name] + :from '([employee "table"] [employee "join"]) + :where [and [= ["table" first-name] + ["join" first-name]] + [not [= ["table" emplid] + ["join" emplid]]]] + :order-by '(["table" last-name]) + :result-types nil :field-names nil) + (("Vladamir" "Lenin") ("Vladamir" "Putin"))) + +(deftest :fdml/select/27 + (clsql:select [coalesce [managerid] 10] :from [employee] :order-by [emplid] + :field-names nil :result-types nil :flatp t) + ("10" "1" "1" "1" "1" "1" "1" "1" "1" "1")) + +(deftest :fdml/select/28 + (loop for column in `([*] [emplid]) collect + (clsql:select [count column] :from [employee] + :flatp t :result-types nil :field-names nil)) + (("10") ("10"))) + +(deftest :fdml/select/29 + (clsql:select [first-name] [last-name] :from [employee] + :result-types nil :field-names nil + :order-by '(([first-name] :asc) ([last-name] :desc))) + (("Boris" "Yeltsin") ("Josef" "Stalin") ("Konstantin" "Chernenko") + ("Leon" "Trotsky") ("Leonid" "Brezhnev") ("Mikhail" "Gorbachev") + ("Nikita" "Kruschev") ("Vladamir" "Putin") ("Vladamir" "Lenin") + ("Yuri" "Andropov"))) + +(deftest :fdml/select/30 + (clsql:select [first-name] [last-name] :from [employee] + :result-types nil :field-names nil + :order-by '(([first-name] :asc) ([last-name] :asc))) + (("Boris" "Yeltsin") ("Josef" "Stalin") ("Konstantin" "Chernenko") + ("Leon" "Trotsky") ("Leonid" "Brezhnev") ("Mikhail" "Gorbachev") + ("Nikita" "Kruschev") ("Vladamir" "Lenin") ("Vladamir" "Putin") + ("Yuri" "Andropov"))) + +(deftest :fdml/select/31 + (clsql:select [last-name] :from [employee] + :set-operation [union [select [first-name] :from [employee] + :order-by [last-name]]] + :flatp t + :result-types nil + :field-names nil) + ("Andropov" "Boris" "Brezhnev" "Chernenko" "Gorbachev" "Josef" "Konstantin" + "Kruschev" "Lenin" "Leon" "Leonid" "Mikhail" "Nikita" "Putin" "Stalin" + "Trotsky" "Vladamir" "Yeltsin" "Yuri")) + +(deftest :fdml/select/32 + (clsql:select [emplid] :from [employee] + :where [= [emplid] [any [select [companyid] :from [company]]]] + :flatp t :result-types nil :field-names nil) + ("1")) + +(deftest :fdml/select/33 + (clsql:select [last-name] :from [employee] + :where [> [emplid] [all [select [groupid] :from [employee]]]] + :order-by [last-name] + :flatp t :result-types nil :field-names nil) +("Andropov" "Brezhnev" "Chernenko" "Gorbachev" "Kruschev" "Putin" "Stalin" + "Trotsky" "Yeltsin")) + +(deftest :fdml/select/34 + (loop for x from 1 below 5 + collect + (car + (clsql:select [last-name] :from [employee] + :where [= [emplid] x] + :flatp t :result-types nil :field-names nil))) + ("Lenin" "Stalin" "Trotsky" "Kruschev")) (deftest :fdml/do-query/1 (let ((result '())) @@ -341,6 +478,21 @@ :order-by [last-name]]) #("Andropov" "Brezhnev" "Chernenko" "Gorbachev" "Kruschev" "Lenin" "Putin" "Stalin" "Trotsky" "Yeltsin")) + +(deftest :fdml/map-query/3 + (clsql:map-query 'list #'identity + [select [last-name] :from [employee] :order-by [last-name]]) + (("Andropov") ("Brezhnev") ("Chernenko") ("Gorbachev") ("Kruschev") ("Lenin") + ("Putin") ("Stalin") ("Trotsky") ("Yeltsin"))) + +(deftest :fdml/map-query/4 + (clsql:map-query 'list #'identity + [select [first-name] [last-name] :from [employee] + :order-by [last-name]]) + (("Yuri" "Andropov") ("Leonid" "Brezhnev") ("Konstantin" "Chernenko") + ("Mikhail" "Gorbachev") ("Nikita" "Kruschev") ("Vladamir" "Lenin") + ("Vladamir" "Putin") ("Josef" "Stalin") ("Leon" "Trotsky") + ("Boris" "Yeltsin"))) (deftest :fdml/loop/1 (loop for (forename surname)