AW: [Zope] multiple optional args to zsql method?

Dieter Fischer dieter.fischer@grid-it.ch
Tue, 26 Nov 2002 10:41:18 +0100


Hello

I'm never using this sqlgroup parameter. Depending on your SQL dialect (I=
'm
using Oracle), you can do something like this:

SELECT columna
=46ROM table
WHERE	columnb =3D NVL(<dtml-sqlvar columnb type=3Dint optional>,columnb)
OR columnc =3D NVL(<dtml-sqlvar columnc type=3Dint optional>,columnc)

So it will produce (when both columns are empty)

SELECT columna
=46ROM table
WHERE	columnb =3D columnb
OR columnc =3D columnc

which will give the same result as

SELECT columna
=46ROM table

HTH

Dieter


>-----Urspr=FCngliche Nachricht-----
>Von: zope-admin@zope.org [mailto:zope-admin@zope.org]Im Auftrag von Skip
>Montanaro
>Gesendet am: Montag, 25. November 2002 20:02
>An: zope@zope.org
>Betreff: [Zope] multiple optional args to zsql method?
>
>I have this ZSQL method:
>
>    <params>
>    id
>    zope_username
>    </params>
>    select * from worker
>      <dtml-sqlgroup where>
>        <dtml-sqltest name=3D"id" op=3D"eq" type=3D"int" optional>
>      <dtml-or>
>        <dtml-sqltest name=3D"zope_username" op=3D"eq" type=3D"string" o=
ptional>
>      </dtml-sqlgroup>
>    ;
>
>When I test it but give no parameters it executes this SQL:
>
>    select * from worker
>      where
>    zope_username =3D ''
>    ;
>
>Since neither id nor zope_username were given shouldn't it have executed
>
>    select * from worker
>    ;
>
>?  I also tried using <dtml-and> instead of <dtml-or>.  Same-o, Same-o.
>
>In addition, if I call it as
>
>    context.sql.get_worker(zope_username=3Duser.getUserName())
>
>from a Python script, it complains "Invalid integer value for id".
>
>I'm flummoxed.
>
>--
>Skip Montanaro - skip@pobox.com
>http://www.mojam.com/
>http://www.musi-cal.com/
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>