module for working with the result set
john fabiani
jfabiani at yolo.com
Mon May 17 23:56:17 EDT 2004
Paul McNett wrote:
> john fabiani writes:
>
>
>>following your thoughts on the keys and my mistake - can you
>>tell me how to get into a dict format?
>
>
> For MySQL, there is the DictCursor class. Here's an example,
> and you should even be able to use it as-is as I've opened up
> public access to my MySQL database:
>
>
>>>>import MySQLdb.cursors
>>>>conn = MySQLdb.connect(host='melder.paulmcnett.com', user='dabo', passwd='dabo', db='dabotest')
>>>>dictCursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
>>>>print dictCursor.execute('select * from recipes where mingred like "%coriander%"')
>
> 14
>
>>>>recordSet = dictCursor.fetchall()
>>>>for record in recordSet:
>
> ... print record['iid'], record['ctitle']
> ...
> 184 Cucumber Salad
> 186 Garlic Shrimps
> 193 Chinese Salad with Crispy Won Tons
> 299 Chicken Curry
> 304 Kai Phat Khing
> 305 Kung Tom Yam
> 306 Ma Ho
> 308 Yam Krachup
> 332 Lentil Soup
> 817 Mixed Vegetable Curry
> 841 Thai Mushroom Soup
> 843 Rice Noodle Salad with Ginger
> 915 Santa Fe Stew
> 966 Mixed Potato Soup
>
>
I know about the MySQL Dictcusor but I'm using Postgres. I'm not
married to Postgres but I had excellent success with it along with a VFP
front end.
BTW is the MySQL Dictclass writen in "C" (part of the driver) or a
python class/module? Maybe I can copy the code if it's python.
thanks
John
More information about the Python-list
mailing list