[Zope] dtml and 'none' behaviour

Garry Saddington garry at scholarpack.org
Fri Feb 11 15:53:13 EST 2005


Thanks you have confirmed what I thought to be the case - avoid nulls in the 
database. It is what my instinct told me but I just wanted to have a Zope 
type view on it.
regards
garry
----- Original Message ----- 
From: "Tino Wildenhain" <tino at wildenhain.de>
To: <garry at scholarpack.org>
Cc: <zope at zope.org>
Sent: Friday, February 11, 2005 7:34 PM
Subject: Re: [Zope] dtml and 'none' behaviour


> Am Freitag, den 11.02.2005, 19:21 +0000 schrieb garry saddington:
>> I have a zsql method which returns some null values. These are then 
>> displayed
>> in a table but the null values become 'None'. Is there any way to get 
>> round
>> this behaviour and have empty cells in the displayed results? I can do it
>> with several dtml-if and dtml-unless calls but wondered if there was a 
>> more
>> subtle approach.
>
> Well, null is to SQL as None to python. So either you solve this
> at database level or in python. For example in python you could
> use:
>
> return [{'foo':row.foo or '',
>         'bar':row.bar or ''} for row in context.yourzsqlmethod()]
>
> with this little "or" you solve this quite elegant. Every
> value which evaluates to false (which is: 0, "", ... and None)
> let the expression return its right side, which is '' in this
> case.
>
>
> On database level you could use coerce() which returns the
> first non null argument:
>
> SELECT coerce(foo,'') as foo,coerce(bar,'') as bar FROM ...
>
> or even better try to avoid nulls where possible.
>
> Regards
> Tino
>
> 



More information about the Zope mailing list