On Thursday 24 January 2008, [EMAIL PROTECTED] wrote:
> Salve!
>
> Problemino irrisolto del giorno:
> devo creare dinamicamente una stringa (e' uno statement WHERE mysql) che ha
> come particolarita' di essere inframezzata ad ogni iterazione da un OR,
> _a_parte_l'_ultima_. Usando una lista farei cosi':
>
>
>
> for y in mylist:
>   if mylist.index(y) < (len(mylist) - 1):
>     var_boole = " OR "
>   else:
>     var_boole = ""
>   where_string = where_string + "field_" + y + " LIKE 'pippo' " + var_boole
> return where_string
> # forse inelegante (accetto volentieri miglioramenti), risultato:
> # se mylist = [ 'uno' , 'due' , 'tre' ], alla fine
>
> # where_string ==
> # field_uno LIKE 'pippo' OR field_due LIKE 'pippo' OR field_tre LIKE
> 'pippo'

conditions = ["field_%s LIKE 'pippo'",]*len(mylist)
conditions = " OR ".join(conditions)
return  'where '+conditions%tuple(mylist)

> ...

non mi è chiaro, ma:

> in PHP andrei ad occhi chiusi, ma python lo sto masticando da una
> settimana...no, ok, due..:-) e mi stro incaprettando con la gestione degli
> arrays

dato che hai dimestichezza con il PHP perchè non usi un metodo DTML SQL? Ha 
proprio i comandi per creare query dinamiche (<dtml-sqlgroup> etc).

-- 
Riccardo Lemmi                           Email:   [EMAIL PROTECTED]
Reflab S.r.l. - Plone Design, Development and Consulting
Phone: +39 349 4620820                         http://www.reflab.it

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Plone-IT mailing list
Plone-IT@lists.plone.org
http://lists.plone.org/mailman/listinfo/plone-it
http://www.nabble.com/Plone---Italy-f21728.html

Rispondere a