[Zope-DB] Z sql Method and using 'OR'

Charlie Clark charlie at begeistert.org
Wed May 5 17:07:50 EDT 2004

Eek! This is one of the reasons I really don't like DTML this is essentially 
duplicating SQL functionality with a lot of impenetrable syntax making 
debugging more difficult because SQL is going to be generated.

On 2004-05-05 at 21:39:57 [+0200], Kent Hoxsey wrote:
> The ZSQL method would have two input parameters, 'username'
> and 'useroffice', and would look like this:
> select * from users u
> <dtml-sqlgroup where> u.user_id = u.user_id
> <dtml-and>
> <dtml-if username>
> <dtml-sqltest username column="u.username" type="string" optional="Yes">
> </dtml-if>
> <dtml-and>
> <dtml-if useroffice>
> <dtml-sqltest useroffice column="u.useroffice" type="string" optional="Yes">
> </dtml-if>
> I know this is a bit complicated and messy, but that's due to ZSQL methods
> using DTML to dynamically define the SQL (switch ZSQL to PageTemplates
> and TAL? we'll save that discussion for another time...) . Stick with me
> and I'll break it down...

I think a good compromise can be achieved like this:

select * from users
<dtml-if username>
(username = <dtml-sqlvar name="username" type="string">
<dtml-if useroffice>
useroffice = <dtml-sqlvar name="useroffice" type="string">

I've got so used to this I haven't even started looking at SQLs own approach 
to flow control...

Now, this only works for either "username" OR "useroffice" but will give a 
syntax error if both are passed. There is an elegant solution to this 


More information about the Zope-DB mailing list