[Zope] sqltest vx. var
Jeffrey P Shell
jeffrey@Digicool.com
Tue, 09 Mar 1999 11:27:49 -0500
>From: Philip Aylesworth <zopelist@regalint.com>
> I'll correct myself here. I was thinking of the <!--#sqlgroup ...--> tag. I
> don't know what <!--#sqltest ...--> does that <!--#sqlvar name--> or
> <!--#var name fmt=sql--> won't do...
A _very very_ nice feature of #sqltest is the 'multiple' feature. For
example:
SELECT * FROM inbox
WHERE <!--#sqltest doc_status type=string multiple-->
If doc_status is passed in as a single value, like "foo", the SQL statement
will be rendered as::
SELECT * FROM inbox
WHERE doc_status='foo'
BUT!!! (this is where it gets good), if doc_status is passed in as a
list/sequence, like ["foo", "bar", "drop", "ship"], it will be rendered
as::
SELECT * FROM inbox
WHERE doc_status in ('foo','bar,'drop','ship')
This is an _extremely_ handy feature of #sqltest. Prior to #sqltest, doing
the above might be like:
SELECT * FROM inbox
WHERE doc_status in (
<!--#in doc_status-->
'<!--#var sequence-item fmt=sql-->'
<!--#else sequence-end-->,<!--#/else-->
<!--#/in-->)
(#else used to be used where #unless is used today). The above code also
always required doc_status to be passed in as a sequence. #sqltest is
smart enough (I believe - i've never been bitten by this) to detect the
difference between strings and lists.
I've used #sqltest with multiple many times with Acquisition where a folder
property would define part of a SQL statement. That property in some cases
would be a single value, in other places it would be a tokens or lines
property.
So, in otherwords, you get the type checking, the multiple, the optional,
etc... with #sqltest that you don't get otherwise. About the only problem
is that #sqltest currently doesn't do not-equals or "not in (...)".
.jPS | jeffrey@digicool.com
zope, through the web. www.zope.org