Anda dapat mengganti rowfactory
kursor metode. Anda perlu melakukan ini setiap kali melakukan kueri.
Inilah hasil kueri standar, sebuah tuple.
curs.execute('select * from foo')
curs.fetchone()
(33, 'blue')
Mengembalikan tuple bernama:
def makeNamedTupleFactory(cursor):
columnNames = [d[0].lower() for d in cursor.description]
import collections
Row = collections.namedtuple('Row', columnNames)
return Row
curs.rowfactory = makeNamedTupleFactory(curs)
curs.fetchone()
Row(x=33, y='blue')
Mengembalikan kamus:
def makeDictFactory(cursor):
columnNames = [d[0] for d in cursor.description]
def createRow(*args):
return dict(zip(columnNames, args))
return createRow
curs.rowfactory = makeDictFactory(curs)
curs.fetchone()
{'Y': 'brown', 'X': 1}
Penghargaan untuk Amaury Forgeot d'Arc:http://sourceforge.net/p/cx-Oracle/mailman/message/27145597