r9188: make result-types :auto the default
[clsql.git] / tests / test-fdml.lisp
index 81fea97ea306c2dddf4ae77d8d28e5bce6ad4bdf..f3b9d13f718ff921f9bbafc966978d320a9fb0e2 100644 (file)
   (("Vladamir" "Lenin" "lenin@soviet.org")))
 
 
+;; Computed values are not always classified as numeric by psqlodbc
 (deftest :fdml/query/1
-    (clsql:query "SELECT COUNT(*) FROM EMPLOYEE WHERE (EMAIL LIKE '%org')")
-  (("10")))
+    (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))
+  10)
 
 (deftest :fdml/query/2
-    (clsql:query
-     "SELECT FIRST_NAME,LAST_NAME FROM EMPLOYEE WHERE (EMPLID <= 5) ORDER BY LAST_NAME")
+    (multiple-value-bind (rows field-names)
+       (clsql:query
+        "SELECT FIRST_NAME,LAST_NAME FROM EMPLOYEE WHERE (EMPLID <= 5) ORDER BY LAST_NAME")
+      (values rows (mapcar 'string-upcase field-names)))
   (("Leonid" "Brezhnev") ("Nikita" "Kruschev") ("Vladamir" "Lenin")
- ("Josef" "Stalin") ("Leon" "Trotsky")))
+   ("Josef" "Stalin") ("Leon" "Trotsky"))
+  ("FIRST_NAME" "LAST_NAME"))
 
+(deftest :fdml/query/3
+    (caar (clsql:query "SELECT EMPLID FROM EMPLOYEE WHERE LAST_NAME = 'Andropov'" :field-names nil))
+  6)
+  
+(deftest :fdml/query/4
+    (typep (caar (clsql:query "SELECT HEIGHT FROM EMPLOYEE WHERE LAST_NAME = 'Andropov'" :field-names nil))
+     'float)
+  t)
   
 (deftest :fdml/execute-command/1
     (values
 
 
 ;; compare min, max and average hieghts in inches (they're quite short
-;; these guys!) -- only works with pgsql 
+;; these guys!) 
 (deftest :fdml/select/1
-    (if (member *test-database-type* '(:postgresql-socket :postgresql))
-        (let ((max (clsql:select [function "floor"
-                                          [/ [* [max [height]] 100] 2.54]]
-                                :from [employee]
-                                :flatp t))
-              (min (clsql:select [function "floor"
-                                          [/ [* [min [height]] 100] 2.54]]
-                                :from [employee]
-                                :flatp t))
-              (avg (clsql:select [function "floor"
-                                          [avg [/ [* [height] 100] 2.54]]]
-                                :from [employee]
-                                :flatp t)))
-          (apply #'< (mapcar #'parse-integer (append min avg max))))
-        t)
+    (let ((max (clsql:select [function "floor"
+                            [/ [* [max [height]] 100] 2.54]]
+                            :from [employee]
+                            :flatp t))
+         (min (clsql:select [function "floor"
+                            [/ [* [min [height]] 100] 2.54]]
+                            :from [employee]
+                            :flatp t))
+         (avg (clsql:select [function "floor"
+                            [avg [/ [* [height] 100] 2.54]]]
+                            :from [employee]
+                            :flatp t)))
+      (apply #'< (mapcar #'(lambda (s) (parse-integer s :junk-allowed t))
+                        (append min avg max))))
   t)
 
 (deftest :fdml/select/2
   ("lenin@soviet.org"))
 
 (deftest :fdml/select/6
-    (if (member *test-database-type* '(:postgresql-socket :postgresql))
-        (mapcar #'parse-integer
-                (clsql:select [function "trunc" [height]] :from [employee]
-                             :flatp t))
-        (mapcar #'(lambda (s) (truncate (parse-integer s :junk-allowed t)))
-                (clsql:select [height] :from [employee] :flatp t)))
+    (if (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]
+                      :flatp t))
+      (mapcar #'(lambda (s) (truncate (parse-integer s :junk-allowed t)))
+       (clsql:select [height] :from [employee] :flatp t)))
   (1 1 1 1 1 1 1 1 1 1))
 
 (deftest :fdml/select/7
                          :flatp t)
             results)
       (apply #'values (nreverse results)))
-  nil :COMMITTED nil ("lenin-nospam@soviet.org") :COMMITTED
+  nil :committed nil ("lenin-nospam@soviet.org") :committed
   nil ("lenin@soviet.org"))
 
 ;; runs a valid update and an invalid one within a transaction and checks