Support :autoincrement for Postgres on table creation by rebuilding what Postgres...
[clsql.git] / sql / oodml.lisp
index e50905e93436755f53f37bbc49ce9f3bcc06412e..d47bbba447ec98914db2b883377c9c941debfdd9 100644 (file)
                                  :av-pairs av-pairs
                                  :database database)
                  (when (and pk-slot (not pk))
-                   (setf pk (if (member :auto-increment (listify (view-class-slot-db-constraints pk-slot)))
+                   (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-autoincrement-id database
+                                      (database-last-auto-increment-id database
                                                                       table
                                                                       pk-slot))))
 
                        (slot-definition s))
             when (sstoredp sd)
               collect sd))
+      ;; 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))))
       ;;this may just be a NOP.
       (setf (slot-value obj 'view-database) database)))