[Zope-DB] sqltest and sqlgroup

Wade Leftwich wade@okaynetwork.com
Tue, 15 Jan 2002 14:18:15 -0500


In my experience, the sqlgroup syntax works just fine for optional select=
=20
arguments.

ZSQL method getReferrals
"""
select * from referrals
<dtml-sqlgroup where>
<dtml-sqltest forename type=3Dstring op=3Deq optional>
<dtml-and>
<dtml-sqltest surname type=3Dstring op=3Deq optional>
</dtml-sqlgroup>
"""

Now here's the trick -- if you want all the Johns, call it like this
getReferrals(forename=3D'John')
or like this
getReferrals({'forename':'John'})

that is, do not pass a surname arg equal to None or ''. That's what the T=
est=20
tab is doing.

--
Wade Leftwich
Ithaca, NY


On Tuesday 15 January 2002 12:01, you wrote:
> From: =3D?iso-8859-1?Q?Dario_Lopez-K=3DE4sten?=3D <dario@ita.chalmers.s=
e>
> To: <zope-db@zope.org>
> Subject: Re: [Zope-DB] sqltest and sqlgroup
> Date: Tue, 15 Jan 2002 11:34:39 +0100
> Organization: CITES
>
> From: "Smith, Neil" <Neil.Smith@npower.com>
> Sent: Tuesday, January 15, 2002 10:32 AM
>
> >=A0I was expecting from the documentation that if I left any of the
> > argumants empty, then that part of the where clause would be ignored,=
 So
> > if I test
>
> it
>
> >=A0and just enter a value of Smith for the surname it should generate =
a
>
> query:
> >=A0 =A0 =A0select * from referrals where surname =3D 'Smith'
> >=A0However, on the test page, and when I try to use it, it always gene=
rates
>
> all
>
> >=A0the clauses, i.e.
> >=A0 =A0 =A0select * from referrals where (title =3D '' and forename =3D=
 '' and
>
> surname
>
> >=A0=3D 'Smith' )
> >=A0Am I doing something wrong, or is it not supposed to work like I th=
ought
>
> it
>
> >=A0should?
>
> It's been like this forever - IIRC there was an entry for this in the
> oldcollector, but I could be mistaken. No fix that I know of, or... may=
be
> using a construct like this:
>
> =A0select * from referrals
> =A0where
> =A0<dtml-if title>
> =A0 title=3D<dtml-sqlvar title type=3Dstring>
> =A0</dtml-if>
> =A0<dtml-if forename>
> =A0 and forename=3D<dtml-sqlvar forename type=3Dstring>
> =A0</dtml-if>
> =A0<dtml-if surename>
> =A0 and surename=3D<dtml-sqlvar surname type=3Dstring>
> =A0</dtml-if>
>
> this is untested and really ugly, though I hope this helps...
>
> /dario