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
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
Can #sqltest handle the 'wildcard' situation in MySQL (and probably other DBMSs too)
select * from tbl where tbl_val like '%nib%' is a different SQL query from select * from tbl where tbl_val = 'niblet'
my attempt...
select * from tbl where <!--#sqltest tbl_val type=string multiple-->
ta Tone. ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
At 10:00 +0000 3/10/99, Tony McDonald wrote:
Can #sqltest handle the 'wildcard' situation in MySQL (and probably other DBMSs too)
select * from tbl where tbl_val like '%nib%' is a different SQL query from select * from tbl where tbl_val = 'niblet'
my attempt...
select * from tbl where
<!--#sqltest tbl_val type=string multiple-->
Hi,
I just dug this up in the archive while realizing I want to do precisely what you're asking: tbl_val like '%nib%'
I couldn't get your example to work. I ended up doing this:
select * from Book <!--#sqlgroup where--> <!--#if "_.len(xauthor)"--> author LIKE <!--#sqlvar xauthor type=string--> <!--#/if--> <!--#and--> <!--#if "_.len(xbookTitle)"--> title LIKE <!--#sqlvar xbookTitle type=string--> <!--#/if--> <!--#/sqlgroup--> order by author, title
where xauthor and xbookTitle are the arguments, and the caller has put '%' on either end of them. I tried adding the '%'s in the SQL method, and this worked when testing the SQL method, but not when it was called from my DTML method.
Doug