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

Charlie Clark charlie at egenix.com
Thu May 6 03:20:06 EDT 2004


On 2004-05-06 at 00:04:58 [+0200], Jim Penny wrote:
> AND ALSO
> ...
> where username=<dtml-sqlvar name="username" type="string">
> <dtml-if useroffice>
>   and useroffice = <dtml-sqlvar name="useroffice" type="string">
> </dtml-if>
> 
> Note that the conjunction has moved inside the dtml-if guard.
> I claim this is MUCH easier to read.
> 
> In general, it is easy to introduce a dummy clause in SQL which
> permits you to have a static first clause, with very little loss of
> efficiency and a large gain in readability.

Total agreement and if you use the following it is totally flexible:

SELECT * FROM table
WHERE 1
<dtml-if var1>
AND myvar = <dtml-sqlvar var1 type="string">
</dtml-if>
...

It is very important to understand that ZSQL-methods should be as close to 
straight SQL as possible just in case you need to talk to a DB expert if 
you have problems or after running EXPLAIN or similar.

Charlie



More information about the Zope-DB mailing list