took me a while to figure out that only strings are supported for :nextval in a :col-default context, so:
lnostdal@blackbox:~/programming/lisp/postmodern/postmodern$ darcs diff -u diff -rN -u old-postmodern/postmodern/table.lisp new-postmodern/postmodern/table.lisp --- old-postmodern/postmodern/table.lisp 2008-10-13 14:11:29.000000000 +0200 +++ new-postmodern/postmodern/table.lisp 2008-10-13 14:11:29.000000000 +0200 @@ -293,6 +293,10 @@ ,(loop :for slot :in (dao-column-slots table) :collect `(,(slot-definition-name slot) :type ,(column-type slot) ,@(when (slot-boundp slot 'col-default) - `(:default ,(column-default slot))))) + `(:default ,(let ((col-def (column-default slot))) + (when (eq :nextval (first col-def)) + (setf (second col-def) + (to-identifier (second col-def)))) + col-def))))) ,@(when (dao-keys table) `((:primary-key ,@(dao-keys table)))))))
..then..
(defclass user () ((id :col-type integer :reader id-of :col-default (:nextval user-id-seq)) ...))
..i don't know.
On Mon, 2008-10-13 at 15:40 +0200, Marijn Haverbeke wrote:
took me a while to figure out that only strings are supported for :nextval in a :col-default context, so:
Cool. Any reason you didn't patch the :nextval operator itself?
Cheers, Marijn
..I think my last message got lost somewhere. This:
diff -rN -u old-postmodern/postmodern/util.lisp new-postmodern/postmodern/util.lisp --- old-postmodern/postmodern/util.lisp 2008-10-13 22:24:03.000000000 +0200 +++ new-postmodern/postmodern/util.lisp 2008-10-13 22:24:03.000000000 +0200 @@ -9,7 +9,7 @@
(defun sequence-next (sequence) "Shortcut for getting the next value from a sequence." - (query (:select (:nextval (to-identifier sequence))) :single)) + (query (:select (:nextval sequence)) :single))
(defmacro make-list-query (relkind) "Helper macro for the functions that list tables, sequences, and diff -rN -u old-postmodern/s-sql/s-sql.lisp new-postmodern/s-sql/s-sql.lisp --- old-postmodern/s-sql/s-sql.lisp 2008-10-13 22:24:03.000000000 +0200 +++ new-postmodern/s-sql/s-sql.lisp 2008-10-13 22:24:03.000000000 +0200 @@ -684,6 +684,9 @@ (def-sql-op :drop-sequence (name) `("DROP SEQUENCE " ,@(sql-expand name)))
+(def-sql-op :nextval (name) + `("nextval('" ,@(sql-expand name) "')")) + (def-sql-op :create-view (name query) ;; does not allow to specify the columns of the view yet `("CREATE VIEW " ,(to-sql-name name) " AS " ,@(sql-expand query)))
..seems to work.
Hello Lars,
Your patch breaks passing strings to :nextval, which might be problematic for existing code. I've pushed a variation that allows both (:nextval "foo") and (:nextval 'foo).
Best, Marijn
postmodern-devel@common-lisp.net