[Zope] Two questions about passing lists to sql methods

Oliver Bleutgen Oliver Bleutgen <myzope@gmx.net>
Tue, 4 Sep 2001 19:56:17 +0200


> I wrote something like this

> select * from table
> where <dtml-in "('a', 'b', 'c')">
>         <dtml-let temp=sequence-item>
>           colum like <dtml-sqlvar "'%' + _.string.strip(temp) + '%'"
> type=string> or
>         </dtml-let>
>         <dtml-if sequence-end>
>           1=2
>         </dtml-if>
>       </dtml-in>

> This worked fine, but when I replaced <dtml-in "('a', 'b', 'c')"> with
> <dtml-in keyWords> and call this method from another page as <dtml-var
> expr="sqlMethod(keyWords=('a', 'b', 'c'))">, nothing returns. Why? I then
> try to pass a list directly using test feature, but no matter what I input
> it always tell me 'no string allowed in the dtml-in function'. What did I
> do wrong?

Hi Jeff,
can't tell you what prevents your method from doing what you want,
but I can tell you what I did what worked in a similar situation.
I use a python script to build the query string and just call that 
method via dtml-var, i.e.

select * from table where <dtml-var my_script>

the script looks like

for s in context.REQUEST['my_dict']:
  query = query + "column LIKE '%" + s + "%'\n OR \n"
query = query + '1=2'
return query

Just make sure that all the variables you need are in REQUEST.

Maybe someone else has a more elegant or cleaner way of doing
things.

cheers,
oliver
PS: nice trick with that 1=2, tho