X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=tests%2Ftest-fdml.lisp;h=f067e1e48c3465352a7303796fa5cff20068786c;hp=56787a21d012bd3bebde380936f8bf31a2842b80;hb=d9f41af62750c622945bb17b622a39689ee5b840;hpb=d9b32644383f3c4087d0ecac10c645f38d17648d diff --git a/tests/test-fdml.lisp b/tests/test-fdml.lisp index 56787a2..f067e1e 100644 --- a/tests/test-fdml.lisp +++ b/tests/test-fdml.lisp @@ -1,7 +1,7 @@ ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*- ;;;; ====================================================================== ;;;; File: test-fdml.lisp -;;;; Author: Marcus Pearce +;;;; Author: Marcus Pearce , Kevin Rosenberg ;;;; Created: 30/03/2004 ;;;; Updated: $Id$ ;;;; @@ -24,10 +24,10 @@ ;; inserts a record using all values only and then deletes it (deftest :fdml/insert/1 - (progn + (let ((now (get-universal-time))) (clsql:insert-records :into [employee] - :values `(11 1 "Yuri" "Gagarin" "gagarin@soviet.org" - 1 1 1.85 t ,(clsql:get-time))) + :values `(11 1 "Yuri" "Gagarin" "gagarin@soviet.org" + 1 1 1.85 t ,(clsql:utime->time now) ,now)) (values (clsql:select [first-name] [last-name] [email] :from [employee] :where [= [emplid] 11]) @@ -133,7 +133,7 @@ (let ((count (caar (clsql:query "SELECT COUNT(*) FROM EMPLOYEE WHERE (EMAIL LIKE '%org')" :field-names nil)))) (if (stringp count) (nth-value 0 (parse-integer count)) - count)) + (nth-value 0 (truncate count)))) 10) (deftest :fdml/query/2 @@ -155,29 +155,38 @@ 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"))) + (let ((res (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))) + (mapcar (lambda (p) (list (car p) (truncate (read-from-string (second p))))) + res)) + (("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")) + (let ((res (clsql:query (clsql:sql [union [select [emplid] :from [employee]] + [select [groupid] :from [company]]]) + :field-names nil :result-types nil :flatp t))) + (values (every #'stringp res) + (mapcar #'(lambda (f) (truncate (read-from-string f))) res))) + 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")) + (let ((res (car (clsql:query (clsql:sql [intersect [select [emplid] :from [employee]] + [select [groupid] :from [company]]]) + :field-names nil :result-types nil :flatp t)))) + (values (stringp res) + (nth-value 0 (truncate (read-from-string res))))) + 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")) + (let ((res (clsql:query (clsql:sql [except [select [emplid] :from [employee]] + [select [groupid] :from [company]]]) + :field-names nil :result-types nil :flatp t))) + (values (every #'stringp res) + (mapcar #'(lambda (f) (truncate (read-from-string f))) res))) + t (2 3 4 5 6 7 8 9 10)) + (deftest :fdml/execute-command/1 (values @@ -222,13 +231,15 @@ "Yuri")) (deftest :fdml/select/3 - (clsql:select [first-name] [count [*]] :from [employee] - :result-types nil - :group-by [first-name] - :order-by [first-name] - :field-names nil) - (("Boris" "1") ("Josef" "1") ("Konstantin" "1") ("Leon" "1") ("Leonid" "1") - ("Mikhail" "1") ("Nikita" "1") ("Vladamir" "2") ("Yuri" "1"))) + (let ((res (clsql:select [first-name] [count [*]] :from [employee] + :result-types nil + :group-by [first-name] + :order-by [first-name] + :field-names nil))) + (mapcar (lambda (p) (list (car p) (truncate (read-from-string (second p))))) + res)) + (("Boris" 1) ("Josef" 1) ("Konstantin" 1) ("Leon" 1) ("Leonid" 1) + ("Mikhail" 1) ("Nikita" 1) ("Vladamir" 2) ("Yuri" 1))) (deftest :fdml/select/4 (clsql:select [last-name] :from [employee] @@ -260,14 +271,20 @@ (1 1 1 1 1 1 1 1 1 1)) (deftest :fdml/select/7 - (clsql:select [max [emplid]] :from [employee] :flatp t - :field-names nil :result-types nil) - ("10")) + (let ((result (car (clsql:select [max [emplid]] :from [employee] :flatp t + :field-names nil :result-types nil)))) + (values + (stringp result) + (nth-value 0 (truncate (read-from-string result))))) + t 10) (deftest :fdml/select/8 - (clsql:select [min [emplid]] :from [employee] :flatp t - :field-names nil :result-types nil) - ("1")) + (let ((result (car (clsql:select [min [emplid]] :from [employee] :flatp t + :field-names nil :result-types nil)))) + (values + (stringp result) + (nth-value 0 (truncate (read-from-string result))))) + t 1) (deftest :fdml/select/9 (subseq @@ -351,7 +368,7 @@ ("1" "2" "3" "4")) (deftest :fdml/select/21 - (clsql:select [substr [first-name] 1 4] :from [employee] + (clsql:select [substring [first-name] 1 4] :from [employee] :flatp t :order-by [emplid] :field-names nil) ("Vlad" "Jose" "Leon" "Niki" "Leon" "Yuri" "Kons" "Mikh" "Bori" "Vlad")) @@ -375,10 +392,11 @@ "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]) + (clsql:select [first-name] :from (clsql-sys:convert-to-db-default-case "employee" *default-database*) + :flatp t :distinct t + :field-names nil + :result-types nil + :order-by [first-name]) ("Boris" "Josef" "Konstantin" "Leon" "Leonid" "Mikhail" "Nikita" "Vladamir" "Yuri")) @@ -394,15 +412,19 @@ (("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")) + (mapcar + (lambda (f) (truncate (read-from-string f))) + (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"))) + (mapcar + (lambda (f) (truncate (read-from-string (car f)))) + (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] @@ -456,6 +478,20 @@ :flatp t :result-types nil :field-names nil))) ("Lenin" "Stalin" "Trotsky" "Kruschev")) +;; test escaping of single quotes +(deftest :fdml/select/35 + (clsql:select "What's up doc?" :from [employee] :flatp t :field-names nil) + ("What's up doc?" "What's up doc?" "What's up doc?" "What's up doc?" + "What's up doc?" "What's up doc?" "What's up doc?" "What's up doc?" + "What's up doc?" "What's up doc?")) + +;; test proper treatment of backslash (depending on backend) +(deftest :fdml/select/36 + (clsql:select "foo\\bar\\baz" :from [employee] :flatp t :field-names nil) + ("foo\\bar\\baz" "foo\\bar\\baz" "foo\\bar\\baz" "foo\\bar\\baz" + "foo\\bar\\baz" "foo\\bar\\baz" "foo\\bar\\baz" "foo\\bar\\baz" + "foo\\bar\\baz" "foo\\bar\\baz")) + (deftest :fdml/do-query/1 (let ((result '())) (clsql:do-query ((name) [select [last-name] :from [employee] @@ -604,8 +640,7 @@ :flatp t) results) (apply #'values (nreverse results))) - nil :committed nil ("lenin-nospam@soviet.org") :committed - nil ("lenin@soviet.org")) + nil nil nil ("lenin-nospam@soviet.org") nil nil ("lenin@soviet.org")) ;; runs a valid update and an invalid one within a transaction and checks ;; that the valid update is rolled back when the invalid one fails. @@ -624,7 +659,7 @@ :av-pairs '((emale "lenin-nospam@soviet.org")) :where [= [emplid] 1])) - (clsql:clsql-error () + (clsql:sql-database-error () (progn ;; check status (push (clsql:in-transaction-p) results) @@ -635,6 +670,7 @@ (apply #'values (nreverse results)))))) nil nil ("lenin@soviet.org")) + )) #.(clsql:restore-sql-reader-syntax-state)