[Zope-DB] optional argument, can it be an empty string
Charlie Clark
charlie at egenix.com
Sat Nov 6 06:17:53 EST 2004
On 2004-11-05 at 20:49:35 [+0100], Kevin Gill <Kevin.Gill at newaddress.ie>
wrote:
> I have a table with forty fields. I use a single Z SQL Method, from
> different places in my code, passing different parameters.
>
> <params>AccountId ControlClientId:optional Mobile:optional </params>
>
> update MyAccount
> set
> <dtml-if ControlClientId>
> ControlClientId = <dtml-sqlvar ControlClientId type=int>,
> </dtml-if>
> <dtml-if Mobile>
> Mobile = <dtml-sqlvar Mobile type=string>,
> </dtml-if>
> accountid = <dtml-sqlvar accountid type=int>
> where
> accountid = <dtml-sqlvar accountid type=int>
>
>
> When I pass in an empty 'Mobile', the above code does not distinguish this
> from an empty string, and the database column is not updated.
>
> Can I detect whether an string was passed in, even if it is empty?
What do you mean by "empty" and "empty string"?
What do you expect to happen when you pass an "empty Mobile"? Are you hoping
to delete entries or set NULLs for "empty Mobile"?
<dtml-if var> will return 0 for non-existant variables and for those which
evaluate as None or false, ie. = None, 0, [], (), {} or "". You could work
around this using an expression instead of a variable but I don't think this
would be a good solution.
Charlie
More information about the Zope-DB
mailing list