[Zope-DB] passing a variable to zsql method

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


Dario Lopez-Kästen wrote:
> 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


forgot to add - you make the zsql method accept User, Model and Serial 
as arguments (in the argument box).

The actual values of those vars can be anything.

Note though that the arguments have to be space-separated - if you use 
commas, they will become part of the variable name, and it will generate 
silent and hard to track errors (I had one of those yesterday whenI 
forgot myself :-P).

another way might be to provide a sort_order variable as an argument. In 
that case the sql would look something like this:

select * from host
order by
<dtml-if expr="sort_order == 'user'">
user
<dtml-elif expr="sort_order == 'model'">
model
<dtml-elif expr="sort_order == 'serial'">
serial
</dtml-if>
/dario

and you call it like, as an example:

context.my_sql_method(sort_order='user', ...)

/dario

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


More information about the Zope-DB mailing list