X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Foodml.lisp;h=b570cedcbb96d6aa8e6ac9b10012ae33e47d2f71;hb=ef93cbe09e01bb540651e6719eb4e8fe7ebeefd0;hp=5cf86230dfdab18cc4018ee9793ea4007bc6e7be;hpb=bdad8b00f0a2359c7990cf994842b809597552ed;p=clsql.git diff --git a/sql/oodml.lisp b/sql/oodml.lisp index 5cf8623..b570ced 100644 --- a/sql/oodml.lisp +++ b/sql/oodml.lisp @@ -265,6 +265,7 @@ (ordered-class-direct-slots view-class) (ordered-class-slots view-class)))) (record-values (mapcar #'slot-value-list slots))) + (cond ((and (not (normalizedp view-class)) (not record-values)) (error "No settable slots.")) @@ -285,18 +286,26 @@ (insert-records :into (sql-expression :table view-class-table) :av-pairs record-values :database database) - (when pk-slot - (if (or (and (listp (view-class-slot-db-constraints pk-slot)) - (member :auto-increment (view-class-slot-db-constraints pk-slot))) - (eql (view-class-slot-db-constraints pk-slot) :auto-increment)) - (setf pk (or pk - (car (query "SELECT LAST_INSERT_ID();" - :flatp t :field-names nil - :database database)))) - (setf pk (or pk - (slot-value obj (slot-definition-name pk-slot)))))) + + (when (and pk-slot (not pk)) + (setf pk (if (or (member :auto-increment (listify (view-class-slot-db-constraints pk-slot))) + (not (null (view-class-slot-autoincrement-sequence pk-slot)))) + (setf (slot-value obj (slot-definition-name pk-slot)) + (database-last-auto-increment-id database + table + pk-slot))))) + (setf pk (or pk + (slot-value + obj (slot-definition-name pk-slot))))) (when (eql this-class nil) - (setf (slot-value obj 'view-database) database))))))) + (setf (slot-value obj 'view-database) database)))))) + ;; handle slots with defaults + (dolist (slot slots) + (when (and (slot-exists-p slot 'db-constraints) + (listp (view-class-slot-db-constraints slot)) + (member :default (view-class-slot-db-constraints slot))) + (update-slot-from-record obj (slot-definition-name slot)))) + pk)) (defmethod delete-instance-records ((instance standard-db-object)) @@ -332,6 +341,7 @@ :result-types nil :database vd)))) (when res + (setf (slot-value instance 'view-database) vd) (get-slot-values-from-view instance (mapcar #'car sels) (car res)))) (pres) (t nil))))) @@ -358,6 +368,7 @@ (res (select att-ref :from view-table :where view-qual :result-types nil))) (when res + (setf (slot-value instance 'view-database) vd) (get-slot-values-from-view instance (list slot-def) (car res)))))) (defmethod update-slot-with-null ((object standard-db-object)