r9450: 22 May 2004 Kevin Rosenberg
[clsql.git] / tests / test-basic.lisp
index 6a27fdd7de0d5f1f7883bfbf2d2044235dd184d0..de3e719fb3e08ad7750d34945a8d9b458954a163 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Author:  Kevin M. Rosenberg
 ;;;; Created: Mar 2002
 ;;;;
 ;;;; Author:  Kevin M. Rosenberg
 ;;;; Created: Mar 2002
 ;;;;
-;;;; $Id: tests.lisp 8926 2004-04-10 21:12:52Z kevin $
+;;;; $Id$
 ;;;;
 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
 ;;;;
 ;;;;
 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
 ;;;;
 
 (in-package #:clsql-tests)
 
 
 (in-package #:clsql-tests)
 
-(defun test-basic-initialize ()
-  (ignore-errors
-   (clsql:execute-command "DROP TABLE TYPE_TABLE"))
-  (clsql:execute-command 
-   "CREATE TABLE TYPE_TABLE (t_int integer, t_float double precision, t_bigint BIGINT, t_str VARCHAR(30))")
-  (dotimes (i 11)
-    (let* ((test-int (- i 5))
-          (test-flt (transform-float-1 test-int)))
-      (clsql:execute-command
-       (format nil "INSERT INTO TYPE_TABLE VALUES (~a,~a,~a,'~a')"
-              test-int
-              (clsql-sys:number-to-sql-string test-flt)
-              (transform-bigint-1 test-int)
-              (clsql-sys:number-to-sql-string test-flt)
-              )))))
-
-(defun test-basic-forms ()
-  (append
-   (test-basic-forms-untyped)
-   '(
-     (deftest :BASIC/TYPE/1
+(setq *rt-basic*
+  '(
+    (deftest :basic/type/1
        (let ((results '()))
          (dolist (row (query "select * from TYPE_TABLE" :result-types :auto)
        (let ((results '()))
          (dolist (row (query "select * from TYPE_TABLE" :result-types :auto)
-                   results)
-           (destructuring-bind (int float bigint str) row
+                  results)
+           (destructuring-bind (int float str) row
              (push (list (integerp int)
                          (typep float 'double-float)
              (push (list (integerp int)
                          (typep float 'double-float)
-                         (if (and (eq :odbc *test-database-type*)
-                                  (eq :postgresql *test-database-underlying-type*))
-                             ;; ODBC/Postgresql may return returns bigints as strings or integer
-                             ;; depending upon the platform
-                             t
-                           (integerp bigint))
                          (stringp str))
                    results))))
                          (stringp str))
                    results))))
-      ((t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t)))
+      ((t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t)))
 
 
-     (deftest :BASIC/TYPE/2
+     (deftest :basic/type/2
         (let ((results '()))
           (dolist (row (query "select * from TYPE_TABLE" :result-types :auto)
                     results)
         (let ((results '()))
           (dolist (row (query "select * from TYPE_TABLE" :result-types :auto)
                     results)
-            (destructuring-bind (int float bigint str) row
+            (destructuring-bind (int float str) row
               (setq results
                     (cons (list (double-float-equal 
                                  (transform-float-1 int)
               (setq results
                     (cons (list (double-float-equal 
                                  (transform-float-1 int)
                           results))))
           results)
        ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
                           results))))
           results)
        ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
-     )))
 
 
-(defun test-basic-forms-untyped ()
-  '((deftest :BASIC/SELECT/1
+  (deftest :basic/select/1
        (let ((rows (query "select * from TYPE_TABLE" :result-types :auto)))
          (values 
           (length rows)
           (length (car rows))))
        (let ((rows (query "select * from TYPE_TABLE" :result-types :auto)))
          (values 
           (length rows)
           (length (car rows))))
-      11 4)
+      11 3)
     
     (deftest :BASIC/SELECT/2
        (let ((results '()))
          (dolist (row (query "select * from TYPE_TABLE" :result-types nil)
                    results)
     
     (deftest :BASIC/SELECT/2
        (let ((results '()))
          (dolist (row (query "select * from TYPE_TABLE" :result-types nil)
                    results)
-           (destructuring-bind (int float bigint str) row
+           (destructuring-bind (int float str) row
              (push (list (stringp int)
                          (stringp float)
              (push (list (stringp int)
                          (stringp float)
-                         (stringp bigint)
                          (stringp str))
                    results))))
                          (stringp str))
                    results))))
-      ((t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t) (t t t t)))
+      ((t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t) (t t t)))
     
     
-    (deftest :BASIC/SELECT/3
+    (deftest :basic/select/3
        (let ((results '()))
          (dolist (row (query "select * from TYPE_TABLE" :result-types nil)
                    results)
        (let ((results '()))
          (dolist (row (query "select * from TYPE_TABLE" :result-types nil)
                    results)
-           (destructuring-bind (int float bigint str) row
-             (declare (ignore bigint))
+           (destructuring-bind (int float str) row
              (push (list (double-float-equal 
                           (transform-float-1 (parse-integer int))
                           (parse-double float))
              (push (list (double-float-equal 
                           (transform-float-1 (parse-integer int))
                           (parse-double float))
                    results))))
       ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
 
                    results))))
       ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
 
-    (deftest :BASIC/MAP/1
+    (deftest :basic/map/1
        (let ((results '())
        (let ((results '())
-             (rows (map-query 'vector #'list "select * from TYPE_TABLE" 
+             (rows (map-query 'vector #'identity "select * from TYPE_TABLE" 
                               :result-types nil)))
          (declare (type (simple-array list (*)) rows))
          (dotimes (i (length rows) results)
                               :result-types nil)))
          (declare (type (simple-array list (*)) rows))
          (dotimes (i (length rows) results)
               (transform-float-1 (parse-integer (first (aref rows i))))
               (parse-double (second (aref rows i)))))
             results)))
               (transform-float-1 (parse-integer (first (aref rows i))))
               (parse-double (second (aref rows i)))))
             results)))
-      ((t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t)))
+      ((t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t)))
     
     
-    (deftest :BASIC/MAP/2
+    (deftest :basic/map/2
        (let ((results '())
        (let ((results '())
-             (rows (map-query 'list #'list "select * from TYPE_TABLE" 
+             (rows (map-query 'list #'identity "select * from TYPE_TABLE" 
                               :result-types nil)))
          (dotimes (i (length rows) results)
            (push
                               :result-types nil)))
          (dotimes (i (length rows) results)
            (push
               (transform-float-1 (parse-integer (first (nth i rows))))
               (parse-double (second (nth i rows)))))
             results)))
               (transform-float-1 (parse-integer (first (nth i rows))))
               (parse-double (second (nth i rows)))))
             results)))
-      ((t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t)))
+      ((t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t)))
     
     
-    (deftest :BASIC/MAP/3
+    (deftest :basic/map/3
            (let ((results '())
            (let ((results '())
-             (rows (map-query 'list #'list "select * from TYPE_TABLE" 
+             (rows (map-query 'list #'identity "select * from TYPE_TABLE" 
                               :result-types :auto)))
              (dotimes (i (length rows) results)
                (push
                               :result-types :auto)))
              (dotimes (i (length rows) results)
                (push
                   (transform-float-1 (first (nth i rows)))
                   (second (nth i rows))))
                 results)))
                   (transform-float-1 (first (nth i rows)))
                   (second (nth i rows))))
                 results)))
-      ((t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t) (t 4 t t)))
+      ((t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t) (t 3 t t)))
 
 
-    (deftest :BASIC/DO/1
+    (deftest :basic/do/1
        (let ((results '()))
        (let ((results '()))
-         (do-query ((int float bigint str) "select * from TYPE_TABLE" :result-types nil)
-           (declare (ignore bigint))
+         (do-query ((int float str) "select * from TYPE_TABLE" :result-types nil)
            (let ((int-number (parse-integer int)))
              (setq results
                    (cons (list (double-float-equal (transform-float-1
            (let ((int-number (parse-integer int)))
              (setq results
                    (cons (list (double-float-equal (transform-float-1
          results)
       ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
 
          results)
       ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
 
-    (deftest :BASIC/DO/2
+    (deftest :basic/do/2
        (let ((results '()))
        (let ((results '()))
-         (do-query ((int float bigint str) "select * from TYPE_TABLE" :result-types :auto)
-           (declare (ignore bigint))
+         (do-query ((int float str) "select * from TYPE_TABLE" :result-types :auto)
            (setq results
                  (cons
                   (list (double-float-equal 
            (setq results
                  (cons
                   (list (double-float-equal 
                   results)))
          results)
       ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
                   results)))
          results)
       ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
+
+
+    (deftest :basic/bigint/1
+       (let ((results '()))
+         (dolist (row (query "select * from TYPE_BIGINT" :result-types :auto)
+                  results)
+           (destructuring-bind (int bigint) row
+             (push (list (integerp int)
+                         (if (and (eq :odbc *test-database-type*)
+                                  (eq :postgresql *test-database-underlying-type*))
+                             ;; ODBC/Postgresql may return returns bigints as strings or integer
+                             ;; depending upon the platform
+                             t
+                           (integerp bigint)))
+                   results))))
+      ((t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t) (t t)))
+
     ))
 
 
     ))
 
 
+(defun test-basic-initialize ()
+  (ignore-errors
+   (clsql:execute-command "DROP TABLE TYPE_TABLE")
+   (clsql:execute-command "DROP TABLE TYPE_BIGINT"))
+
+  (clsql:execute-command 
+   "CREATE TABLE TYPE_TABLE (t_int integer, t_float double precision, t_str VARCHAR(30))")
+
+  (if (clsql-sys:db-type-has-bigint? *test-database-type*)
+    (clsql:execute-command "CREATE TABLE TYPE_BIGINT (t_int integer, t_bigint BIGINT)")
+    (clsql:execute-command "CREATE TABLE TYPE_BIGINT (t_int integer)"))
+
+  (dotimes (i 11)
+    (let* ((test-int (- i 5))
+          (test-flt (transform-float-1 test-int)))
+      (clsql:execute-command
+       (format nil "INSERT INTO TYPE_TABLE VALUES (~a,~a,'~a')"
+              test-int
+              (clsql-sys:number-to-sql-string test-flt)
+              (clsql-sys:number-to-sql-string test-flt)
+              ))
+      (when (clsql-sys:db-type-has-bigint? *test-database-type*)
+       (clsql:execute-command
+        (format nil "INSERT INTO TYPE_BIGINT VALUES (~a,~a)"
+                test-int
+                (transform-bigint-1 test-int)
+                ))))))
+
 ;;;; Testing functions
 
 (defun transform-float-1 (i)
 ;;;; Testing functions
 
 (defun transform-float-1 (i)