MySQLdb DictCursor scrambles field order

Gerhard Haering gerhard.haering at gmx.de
Thu Aug 1 03:40:14 EDT 2002


In article <62e69c0c.0207312258.71bc5c59 at posting.google.com>, HW wrote:
> "Chris Gonnerman" <chris.gonnerman at newcenturycomputers.net>:
>> ----- Original Message ----- 
>> From: "HW" <google at thegoldensun.com>
>> > Hello,
>> > 
>> > I am viewing some MySQL tables via Python CGI; [...] Unfortunately, the
>> > DictCursor seems to scramble the order of fields, [...]
> 
>> What else did you expect?  The fields are returned in the form of a 
>> mapping, which has no required or inate order to it.  It's a hash.
>> 
>> Again, why do you care?  
> 
> I care because I am returning the results of an arbitrary
> (user-specified) query. I have considered parsing the SELECT clause of
> their SQL query

Just look into cursor.description. It can be used to get the fields in an
ordered way.

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')))



More information about the Python-list mailing list