[Zope-DB] passing a variable to zsql method

Dario Lopez-Kästen dario at ita.chalmers.se
Sat Sep 4 05:17:03 EDT 2004


Laura McCord wrote:
> if I have a zsql method that looks like this:
> 
> Select * from host 
> Order By ....
> 
> And I call the zsql method like this:
> ...here/resultTable(User) or
> ...here/resultTable(Model) or 
> ...here/resultTable(Serial)
> 
> How do I modify my zsql method to accept any of these parameters and
> replace the Order By so if I call here/resultTable(User), it will order
> by User? Or, if I call the method as here/resultTable(Model), it will
> order by Model?
> 
> I guess I was just checking to see if this is possible or do I have to
> have a separate method for each sort.
> 


select * from host
order by
<dtml-if User>
user
<dtml-elif Model>
model
<dtml-elif Serial>
serial
</dtml-if>

I am sure that there are more elegant ways of doing this, but this works 
quite well.

Hope this helps

/dario


-- -------------------------------------------------------------------
Dario Lopez-Kästen, IT Systems & Services Chalmers University of Tech.


More information about the Zope-DB mailing list