made the datetest table have a key column so that update-records-from-* works again
[clsql.git] / tests / test-time.lisp
index 39cc93061bfe5e59520480a82f6bb3022e0e3c23..e5b4d64befccba2ea7190fe17e99e7fc991a52e1 100644 (file)
@@ -1,26 +1,34 @@
 ;;; -*- Mode: Lisp -*-
-;;; $Id$
 ;;;
 ;;; Copyright (c) 2000, 2001 onShore Development, Inc.
 ;;;
 ;;; Test time functions (time.lisp)
 
 (in-package #:clsql-tests)
-#.(clsql-sys:locally-enable-sql-reader-syntax)
+(clsql-sys:file-enable-sql-reader-syntax)
 
 (def-view-class datetest ()
-  ((testtimetz :COLUMN "testtimetz" :TYPE
-              clsql-sys:wall-time :DB-KIND :BASE
-              :DB-CONSTRAINTS COMMON-LISP:NIL
-              :ACCESSOR testtimetz :INITARG
-              :testtimetz :INITFORM COMMON-LISP:NIL
-              :DB-TYPE "timestamp with time zone")
-   (testtime :COLUMN "testtime" :TYPE
-            clsql-sys:wall-time :DB-KIND :BASE
-            :DB-CONSTRAINTS COMMON-LISP:NIL
-            :ACCESSOR testtime :INITARG
-            :testtime :INITFORM COMMON-LISP:NIL
-            :DB-TYPE "timestamp without time zone")))
+  ((id :column "id"
+                :type integer
+                :db-kind :key
+                :db-constraints (:not-null :unique)
+               :accessor id :initarg :id
+                :initform nil
+               :db-type "int4")
+   (testtimetz :column "testtimetz"
+                :type clsql-sys:wall-time
+                :db-kind :base
+                :db-constraints nil
+               :accessor testtimetz :initarg :testtimetz
+                :initform nil
+               :db-type "timestamp with time zone")
+   (testtime :column "testtime"
+             :type clsql-sys:wall-time
+             :db-kind :base
+            :db-constraints nil
+            :accessor testtime :initarg :testtime
+             :initform nil
+            :db-type "timestamp without time zone")))
 
 (def-dataset *ds-datetest*
   (:setup (lambda () (clsql-sys:create-view-from-class 'datetest)))
                                  :values (list time))
        (let ((testtime
               (first (clsql:select [testtime]
-                                   :from [datetest] :flatp T
+                                   :from [datetest] :flatp t
                                    :where [= [testtime] time] ))))
          (format-time nil (parse-timestring testtime) :format :iso)
          )))
                                  :values (list time))
        (let ((testtime
               (first (clsql:select [testtime]
-                                   :from [datetest] :flatp T
+                                   :from [datetest] :flatp t
                                    :where [= [testtime] time] ))))
          (format-time nil (parse-timestring testtime) :format :iso)
          )))
                                  :values (list time))
        (let ((testtime
               (first (clsql:select [testtime]
-                                   :from [datetest] :flatp T
+                                   :from [datetest] :flatp t
                                    :where [= [testtime] time] ))))
          (format-time nil (parse-timestring testtime) :format :iso)
          )))
                                  :values (list time))
        (let ((testtime
               (first (clsql:select [testtime]
-                                   :from [datetest] :flatp T
+                                   :from [datetest] :flatp t
                                    :where [= [testtime] time] ))))
          (format-time nil (parse-timestring testtime) :format :iso)
          )))
        (let ((testtime
               (first (clsql:select [testtime]
                                    :from [datetest]
-                                   :limit 1 :flatp T
+                                   :limit 1 :flatp t
                                    :where [= [testtime] time] ))))
          (format-time nil (parse-timestring testtime) :format :iso)
          )))
   (with-dataset *ds-datetest*
     (let ((time (parse-timestring "2008-09-09T14:37:29.000213-04:00")))
       (clsql-sys:insert-records :into [datetest]
-                               :attributes '([testtimetz] [testtime])
-                               :values (list time time))
+                               :attributes '([testtimetz] [testtime] [id])
+                               :values (list time time 1))
       (destructuring-bind (testtimetz testtime)
          (first (clsql:select [testtimetz] [testtime]
                               :from [datetest]
-                              :limit 1 :flatp T
+                              :limit 1 :flatp t
                               :where [= [testtime] time] ))
        (values (iso-timestring (parse-timestring testtime))
                (iso-timestring (parse-timestring testtimetz))))))
   (with-dataset *ds-datetest*
     (let ((time (parse-timestring "2008-09-09T14:37:29-04:00")))
       (clsql-sys:update-records-from-instance
-       (make-instance 'datetest :testtimetz time :testtime time))
+       (make-instance 'datetest :testtimetz time :testtime time :id 1))
       (let ((o (first (clsql:select
                          'datetest
-                       :limit 1 :flatp T
+                       :limit 1 :flatp t
                        :where [= [testtime] time] ))))
        (assert o (o) "o shouldnt be null here (we should have just inserted)")
        (update-records-from-instance o)
     (with-dataset *ds-datetest*
       (let ((time (parse-timestring "2008-09-09T14:37:29.000278-04:00")))
        (clsql-sys:update-records-from-instance
-        (make-instance 'datetest :testtimetz time :testtime time))
+        (make-instance 'datetest :testtimetz time :testtime time :id 1))
        (let ((o (first (clsql:select
                         'datetest
-                        :limit 1 :flatp T
+                        :limit 1 :flatp t
                         :where [= [testtime] time] ))))
          (assert o (o) "o shouldnt be null here (we should have just inserted)")
          (update-records-from-instance o)
     #.(iso-timestring (parse-timestring "2008-09-09T14:37:29.000278-04:00"))
     #.(iso-timestring (parse-timestring "2008-09-09T14:37:29.000278-04:00")))
 
+(deftest :time/historic-datetimes
+  (with-dataset *cross-platform-datetest*
+    (let ((time (parse-timestring "1800-09-09T14:37:29")))
+      (clsql-sys:insert-records :into [datetest]
+                                :attributes '([testtime])
+                                :values (list time))
+      (let ((testtime
+              (first (clsql:select [testtime]
+                       :from [datetest] :flatp t
+                       :where [= [testtime] time] ))))
+        (format-time nil (parse-timestring testtime) :format :iso)
+        )))
+  #.(format-time nil (parse-timestring "1800-09-09T14:37:29") :format :iso))
+
 ))
 
 
-#.(clsql-sys:locally-disable-sql-reader-syntax)
+
+
+