From 765abda7aa096d8fd7adab0c8d82c84ade34e65b Mon Sep 17 00:00:00 2001 From: Roger Binns Date: Thu, 22 Jan 2015 17:17:22 -0800 Subject: [PATCH] Show how to do a dict row factory --- doc/tips.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/tips.rst b/doc/tips.rst index 959e2c5d..9722342b 100644 --- a/doc/tips.rst +++ b/doc/tips.rst @@ -159,7 +159,14 @@ appropriate. The cursor only has two important methods - If you want to change the rows returned then use a :ref:`row tracer `. For example you could call :meth:`Cursor.getdescription` and return a dictionary instead of a -tuple. +tuple:: + + def row_factory(cursor, row): + return {k[0]: row[i] for i, k in enumerate(cursor.getdescription())} + + # You can also set this on just a cursor + connection.setrowtrace(row_factory) + .. _busyhandling: