[Zope-DB] using dtml-if in ZSQL method

Jeff Kowalczyk jtk@yahoo.com
Tue, 12 Nov 2002 12:07:36 -0500


How do I use dtml-if to conditionally insert an order by sort order modifier? Passing
reverse=1 to this method doesn't give the desired insertion.

<params>ShipmentDate=11/06/2002
sort=ShipmentID
reverse=0</params>
select ShipmentID, ShipmentDate, LocationAddress
from Shipments
where <dtml-sqltest ShipmentDate op=eq type=string>
and ShipperID = 'MyShipper'
and DeliveredTo is not null
order by <dtml-var sort sql_quote> <dtml-if expr="reverse==1">desc</dtml-if>

Changing the 'reverse=0' parameter default to an 'order=asc' would be easier (same
technique as sort) but I wanted to stay close to the ZPT FileLibrary sample and its
getFiles script while I'm getting my feet wet using ZSQL from ZPT, and might I as well
learn how to do this kind of SQL insertion in the meantime. Thanks.