[Zope-DB] ZSQL and update, what is the correct way to deal with
nulls?
Matthew T. Kromer
matt@zope.com
Tue, 06 May 2003 16:25:30 -0400
David Wilbur wrote:
>
> hi,
> i was hoping that someone could describe to me what is the right way
> to deal with null and zsql methods. i have come up with the following
> _EXAMPLE_ below that works... but, this table only has one field that
> allows null and i'm sitting here saying to my self... wow, what if it
> had like 10 permutations of nulls? i just cant envision that i would
> have to write 10 zsql methods. i figure that i must be missing
> something in the rather sparse documentation on zsql...
>
> is 'None' the normal way that zsql indicates null when you do a
> select [colums] from [table name]? How do you distinguish between the
> string 'None' and when it is indicating that the value is null?
>
None is different from "None". In Python, None is a special singleton
object. Most database adapters will map the value NULL for a column
into None, and vice versa. However, if you accidentally convert the
column value into a string, you lose the ability to distinguish between
None and "None."
Beware of using dtml-var to generate form input, it will convert None to
"None" for you. Note that there IS no way to represent None in a form
variable to my knowledge -- None has no web representation. You usually
must convert "" to None if that is your intent.
--
Matt Kromer
Zope Corporation http://www.zope.com/