有些dbi2的數(shù)據(jù)庫(kù)實(shí)現(xiàn)了fetchoneDict接口,畢竟不是強(qiáng)制要求的,但是實(shí)際應(yīng)用中非常有用
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