MySQLdb where's fetchoneDict()?

Gerhard Häring gh_pythonlist at gmx.de
Sun Sep 30 14:44:05 CEST 2001


On Sun, Sep 30, 2001 at 12:33:33PM +0200, Gabriel Ambuehl wrote:
> Hello Gerhard,
> 
> Sunday, September 30, 2001, 11:31:22 AM, you wrote:
> > There's no fetchoneDict() in the Python DB-API. So I think yes, you
> > should rewrite code that uses this. Sticking to the DB-API and using
> > portable SQL will also ensure that you can easily switch to a
> > different databaes, should you ever need that.
> 
> AARGH. That means I can go and rewrite 2000 lines of code. (I wouldn't
> mean not being portable...)

I think it's classified as "deprecated" because it's nonstandard.

I don't think you have to replace all fetchoneDict() with fetchone() and
ugly integer indices.

I'd probably subclass the cursor class to have the desired behaviour, i.
e. a fetchoneDict() method that only uses stuff from the DB-API. That's
not too difficult, it would only involve cursor.fetchone() and
cursor.description. Then you'd need to subclass the Connection class to
return an instance of your subclassed Cursor class instead.

I think Andy Dustman has something called dbObj on his homepage that
seems to do something similar.

HTH,

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20010930/db161790/attachment.pgp>


More information about the Python-list mailing list