[DB-SIG] Optional DB API Extensions

M.-A. Lemburg mal@lemburg.com
Wed, 24 Oct 2001 13:35:10 +0200


Magnus Lyck=E5 wrote:
>=20
> > > and if it cannot determine the value it should return -1
> > > (this simplifies checking and is more in sync with the other attrib=
utes).
>=20
> At 11:04 2001-10-24 +0200, Federico Di Gregorio wrote:
> >i don't think it should return a numeric value. -1 _can_ be a valid
> >rowid on some dbs. None is better, imho.
>=20
> I also dislike "-1". Using special values of the normal set of
> return values is a bad idea.=20

Agreed.=20

I didn't know that -1 was in fact a valid ROWID; changed
to None again.

> I remember the beginning of January
> 1999. The PBX's at Swedish hospitals didn't work. I couldn't
> rent a car because the "system" was down and so on. Year =3D 99
> must mean ERROR, right? I could well imagine that someone who
> is used to the Python way of handling lists would assume that
> -1 meant the last object. I could even imagine that someone
> will eventually make some kind of wrapper so that the rowids
> can be used like list indices etc.

True, but that wrapper can easily include the needed code to
handle negative returns of e.g. .rownumber and then map
this to some kind of exception.
=20
> After all these years I still make mistakes with string.find()...
> I'm not suggesting that string.find should raise an exception
> or return None if nothing is found. After all, not finding a
> character in a string is something normal, hardly exceptional,
> and both 0 and None are "false", so returning None would be
> an invitation to bugs. But I still think the "-1" is a wart.

Not really: -1 is not in the set of valid values since the
return value is meant to be an index into a sequence (of=20
characters) and indexes start at 0.

> Is it a terrible thing to raise an exception here? After all,
> if I request a value from a module that doesn't know how to
> supply that, I think that is a candidate for an exception. Or
> did I misunderstand something?

It's mainly a performance question: raising exceptions is very
expensive and should only be done for unexpected behaviour.
OTOH, checking for negative results when querying e.g. .rowcount of
.rownumber is fast.

--=20
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/