MySQLdb and dictcursor

blank blank at stare.com
Fri Jul 28 20:04:50 EDT 2006


Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote in 
news:duu9c2pppiqv45pg9a8moh02733njcb7ch at 4ax.com:

>      dictCursor
>           RETURNS the results as a dictionary; it doesn't affect how
> parameters are passed in.

thats how I was using it


> 
>      Normally results are a (list or tuple) where you have to know the
> order of the fields specified in the query:
> 
>      cr.execute("select a, c, b from table")
>      dt = cr.fetchone()
> 
> dt is a (list/tuple) with (a_value, c_value, b_value)
> 
>      With a dictCursor you get
> 
>      dcr.execute("select a, c, b from table")
>      ddt = dcr.fetchone()
> 
> ddt is a dictionary of {"a" : a_value, "b" : b_value, "c" : c_value}
> 
> 
>      MySQLdb nominally uses just the %s placeholder style, but I think 
it
> will also function with %(name)s format...
> 
>      cr.execute(
>           "insert into table (c, a, b) values (%(c)s, %(a)s, %(b)s",
>           ddt)

sounds a lot simpler, ill give it a go later. thanks





More information about the Python-list mailing list