[Zope-DB] optional argument, can it be an empty string

Remy Pinsonnault remy_pinsonnault at roche.ca
Mon Nov 8 08:44:43 EST 2004


What about

     <dtml-if Mobile>
         Mobile = <dtml-sqlvar Mobile type=string>,
     <dtml-else>
         Mobile = NULL,
     </dtml-if>

-----Original Message-----
From: zope-db-bounces at zope.org [mailto:zope-db-bounces at zope.org] On Behalf
Of Charlie Clark
Sent: Sábado, 06 de Noviembre de 2004 06:18 a.m.
To: Kevin Gill
Cc: zope-db at zope.org
Subject: Re: [Zope-DB] optional argument, can it be an empty string



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
_______________________________________________
Zope-DB mailing list
Zope-DB at zope.org
http://mail.zope.org/mailman/listinfo/zope-db



More information about the Zope-DB mailing list