I looked at a lot of different ways of doing this, and it looks like
the django.db cursor needs to be hacked to support MySQLdb's
DicCursor. That seems overkill since its easy to just import MySQLdb
yourself, and the prebuild django.db libraries are mostly just for the
Models. Your other option is to use your own method to create the
dictionary.
def query(cursor, sql):
    cursor.execute(sql)
    columns = range(len(cursor.description))
    while True:
        result = cursor.fetchone()
        if not result:
            raise StopIteration
        row = {}
        for column in columns:
            row[cursor.description[column][0]] = result[column]
        yield row




On Feb 11, 4:25 am, Dirk Eschler <[EMAIL PROTECTED]> wrote:
> On Freitag, 9. Februar 2007, Dirk Eschler wrote:
>
> > Hello,
>
> > is there a way to get a dictcursor from Django when using custom MySQL?
>
> > >from django.db import connection
>
> > cursor = connection.cursor()
> > cursor.execute("SELECT [...]")
> > cursor.fetchall()
>
> > The above fetchall returns a tuple, while i need a dict, like it is built
> > with MySQLdb.cursors.DictCursor(db).
>
> In case it's not possible: can i reuse Django's connection object somehow, or
> do i have to handle the connection myself?
>
> Is there any Django/MySQLdb example maybe?
>
> Best Regards,
> Dirk Eschler
>
> --
> Dirk Eschler <mailto:[EMAIL PROTECTED]>http://www.krusader.org


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to