Skip Montanaro writes:
I have this ZSQL method:
<params> id zope_username </params> select * from worker <dtml-sqlgroup where> <dtml-sqltest name="id" op="eq" type="int" optional> <dtml-or> <dtml-sqltest name="zope_username" op="eq" type="string" optional> </dtml-sqlgroup> ;
When I test it but give no parameters it executes this SQL:
select * from worker where zope_username = '' ;
Since neither id nor zope_username were given shouldn't it have executed
select * from worker ; "optional" suppresses the "sqltest" when the value cannot be converted into the target type.
The empty id cannot be converted into "int" (--> suppression) but the empty "zope_username" is a perfect string. Use "type=nb" (for "non-blank") to suppress emty string tests.
.... In addition, if I call it as
context.sql.get_worker(zope_username=user.getUserName())
from a Python script, it complains "Invalid integer value for id". As you do not pass the "id" parameter, it acquires it.
As you can see, the acquired "id" is not an integer, which is not really a surprise. Either define a default value for "id" or pass it explicitely. I agree that Z SQL methods should not implicitly acquire parameters: You should have gotten a "Bad request" exception: "missing parameter id". Please file a bug report to the collector (<http://collector.zope.org>). Dieter