MySQLdb where's fetchoneDict()?
Skip Montanaro
skip at pobox.com
Sun Sep 30 09:50:01 EDT 2001
Gabriel> I wonder whether there's a fetchoneDict() equivalent to
Gabriel> fetchallDict() in version 0.9 in case one wants to fetch only
Gabriel> one row and thus don't want to have the data in a a list of
Gabriel> dictionaries. (The reason I don't just want to use fetchone()
Gabriel> is that I've got tables with some 20 fields and it's rather
Gabriel> hard to handle that many fields in a tuple when you have only
Gabriel> numerical indexes in order to access them...).
Gabriel,
When you create the database connection you can specify the type of cursor
to use by passing a cursorclass parameter, e.g.:
self.db = MySQLdb.Connection(host=self.host,
user=self.user,
passwd=self.password,
db=self.database,
cursorclass=MySQLdb.cursors.DictCursorNW)
Try pydoc.help(MySQLdb.cursors) for all the possibilities...
--
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/
More information about the Python-list
mailing list