有些dbi2的数据库实现了fetchoneDict接口,毕竟不是强制要求的,但是实际应用中非常有用
import sys,sqlite3,os
def fetchoneDict(cr):
ff = [ r[0] for r in cr.description ]
rr = cr.fetchone()
if rr:
return dict( zip(ff,rr) )
return {}
cnn = sqlite3.connect('e:/tax.db3')
print dir(sqlite3)
cr = cnn.execute('select * from core_bill')
while 1:
r = fetchoneDict(cr)
if not r: break
print r