[DB-SIG] DbiDate testing for None

M.-A. Lemburg lemburg@uni-duesseldorf.de
Wed, 04 Mar 1998 16:36:46 +0100


perry@ns.ac-copy.com wrote:
> 
> |hi:
> |
> |i recently ran into the problem where testing for None for a DbiDate object
> |causes a segfault.  i searched the net and found a post on 3/17/97
> |regarding the problem but have seen no followup.    I'm currently avoiding
> |the problem by testing "type(x) is not NoneType".  does anyone know of a
> |solution or better work-around?
> |
> |
> |this happens on solaris using oracledb and on NT4.0 (pythonwin and python)
> |using odbc.
> |
> 
> This also happens on linux with adabas using mxODBC.
> 

Ouchh. This nb_nonzero-slot of the numeric protocol is not NULL
checked when doing a PyObject_IsTrue()-call with a DateTime
instance: that's what causes it to fail for mxODBC.

I'll provide that slot in the next release of mxDateTime.
Since you only wanted to check for None, this method might
help:

value,date = c.fetchone()
if date is None:
	print 'Now what... ?'
else:
	print 'OK'

It avoids the 'is true' check (it only checks for identity
which works in this case since None is a singleton).

PS: Could it be that the odbc DbiDate has the same problem ?

-- 
Marc-Andre Lemburg


_______________
DB-SIG  - SIG on Tabular Databases in Python

send messages to: db-sig@python.org
administrivia to: db-sig-request@python.org
_______________