Update-slots-from-instance now throws an exception if it generates an update without...
[clsql.git] / sql / metaclasses.lisp
index 0d6471b19654fdeeb722dc16ffa5eec3626edccb..6ee6d4d062062c536035f297e5a1d337e4b194e3 100644 (file)
@@ -46,8 +46,8 @@
    (key-slots
     :accessor key-slots
     :initform nil)
-   (normalisedp
-    :accessor normalisedp
+   (normalizedp
+    :accessor normalizedp
     :initform nil)
    (class-qualifier
     :accessor view-class-qualifier
                                           base-table))
                                  (class-name class)))))
 
+(defgeneric ordered-class-direct-slots (class))
 (defmethod ordered-class-direct-slots ((self standard-db-class))
   (let ((direct-slot-names
          (mapcar #'slot-definition-name (class-direct-slots self)))
 (defmethod initialize-instance :around ((class standard-db-class)
                                         &rest all-keys
                                         &key direct-superclasses base-table
-                                        qualifier normalisedp
+                                        qualifier normalizedp
                                         &allow-other-keys)
   (let ((root-class (find-class 'standard-db-object nil))
         (vmc 'standard-db-class))
                    (remove-keyword-arg all-keys :direct-superclasses)))
         (call-next-method))
     (set-view-table-slot class base-table)
-    (setf (normalisedp class) (car normalisedp))
+    (setf (normalizedp class) (car normalizedp))
     (register-metaclass class (nth (1+ (position :direct-slots all-keys))
                                    all-keys))))
 
 (defmethod reinitialize-instance :around ((class standard-db-class)
                                           &rest all-keys
-                                          &key base-table normalisedp
+                                          &key base-table normalizedp
                                           direct-superclasses qualifier
                                           &allow-other-keys)
   (let ((root-class (find-class 'standard-db-object nil))
         (vmc 'standard-db-class))
     (set-view-table-slot class base-table)
-    (setf (normalisedp class) (car normalisedp))
+    (setf (normalizedp class) (car normalizedp))
     (setf (view-class-qualifier class)
           (car qualifier))
     (if (and root-class (not (equal class root-class)))
     (setf (key-slots class) (remove-if-not (lambda (slot)
                                              (eql (slot-value slot 'db-kind)
                                                   :key))
-                                           (if (normalisedp class)
+                                           (if (normalizedp class)
                                                (ordered-class-direct-slots class)
                                                (ordered-class-slots class))))))
 
   (setf (key-slots class) (remove-if-not (lambda (slot)
                                            (eql (slot-value slot 'db-kind)
                                                 :key))
-                                         (if (normalisedp class)
+                                         (if (normalizedp class)
                                              (ordered-class-direct-slots class)
                                              (ordered-class-slots class)))))
 
@@ -313,7 +314,13 @@ column definition in the database.")
     :accessor specified-type
     :initarg specified-type
     :initform nil
-    :documentation "Internal slot storing the :type specified by user.")))
+    :documentation "Internal slot storing the :type specified by user.")
+   (autoincrement-sequence
+    :accessor view-class-slot-autoincrement-sequence
+    :initarg :autoincrement-sequence
+    :initform nil
+    :documentation "A string naming the (possibly automatically generated) sequence
+for a slot with an :auto-increment constraint.")))
 
 (defparameter *db-info-lambda-list*
   '(&key join-class
@@ -424,7 +431,7 @@ implementations."
             specified-type))))
     (if (and type (not (member :not-null (listify db-constraints))))
         `(or null ,type)
-      type)))
+        (or type t))))
 
 ;; Compute the slot definition for slots in a view-class.  Figures out
 ;; what kind of database value (if any) is stored there, generates and
@@ -452,8 +459,10 @@ implementations."
           (slot-definition-name obj)))
   (apply #'call-next-method obj
          'specified-type type
-         :type (compute-lisp-type-from-specified-type
-                type db-constraints)
+         :type (if (and (eql db-kind :virtual) (null type))
+                   t
+                   (compute-lisp-type-from-specified-type
+                    type db-constraints))
          initargs))
 
 (defmethod compute-effective-slot-definition ((class standard-db-class)
@@ -523,6 +532,14 @@ implementations."
 
          (setf (specified-type esd)
                (delistify-dsd (specified-type dsd)))
+         ;; In older SBCL's the type-check-function is computed at
+         ;; defclass expansion, which is too early for the CLSQL type
+         ;; conversion to take place. This gets rid of it. It's ugly
+         ;; but it's better than nothing -wcp10/4/10.
+         #+(and sbcl #.(cl:if (cl:and (cl:find-package :sb-pcl)
+                                      (cl:find-symbol "%TYPE-CHECK-FUNCTION" :sb-pcl))
+                              '(cl:and) '(cl:or)))
+         (setf (slot-value esd 'sb-pcl::%type-check-function) nil)
 
          )
         ;; all other slots