r10077: * multiple: Apply patch from Joerg Hoehle with multiple
[clsql.git] / tests / test-fdml.lisp
index 56787a21d012bd3bebde380936f8bf31a2842b80..f067e1e48c3465352a7303796fa5cff20068786c 100644 (file)
@@ -1,7 +1,7 @@
 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
 ;;;; ======================================================================
 ;;;; File:    test-fdml.lisp
-;;;; Author:  Marcus Pearce <m.t.pearce@city.ac.uk>
+;;;; Author:  Marcus Pearce <m.t.pearce@city.ac.uk>, Kevin Rosenberg
 ;;;; Created: 30/03/2004
 ;;;; Updated: $Id$
 ;;;;
        
 ;; 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])
     (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
   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
   "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] 
  (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 
  ("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"))
 
   "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"))
 
  (("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] 
                  :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]
                          :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. 
                                  :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)
             (apply #'values (nreverse results))))))
   nil nil ("lenin@soviet.org"))
 
+
 ))
 
 #.(clsql:restore-sql-reader-syntax-state)