[postmodern-devel] Building s-sql on the fly

Jens Teich info at jensteich.de
Thu Dec 11 15:05:05 UTC 2008


Phil schrieb:
> Hi 
> 
> I am looking for an example of how to create a s-sql query on the fly. I
> am sure I saw something like that along the line on some website but I
> cant find it again.

Are you looking for things like that:

(defun element (&key guid guid-parent type-id type-not-equal)
   (let ((sql-guid        (if guid
                            (postmodern:sql (:= 'guid guid))
                            (postmodern:sql t)))
         (sql-guid-parent (if guid-parent
                            (postmodern:sql
                              (:= 'struct-guid-parent-node guid-parent))
                            (postmodern:sql t)))
         (sql-type-id     (if type-id
                            (postmodern:sql (:= 'type-id type-id))
                            (postmodern:sql t)))
         (sql-type-not-equal (if type-not-equal
                               (postmodern:sql
                                 (:not (:= 'type-id type-not-equal)))
                               (postmodern:sql t))))
        (postmodern:query (:order-by
                           (:select 'guid 'name 'type-id 'name-css
                            :from   'projekt-elemente
                            :where  (:and
                                     (:raw sql-guid)
                                     (:raw sql-guid-parent)
                                     (:raw sql-type-id)
                                     (:raw sql-type-not-equal)
                                     (:= 'lang-id *lang*)))
                           'struct-sort-order))))

Jens




More information about the postmodern-devel mailing list