这些抓取有什么区别?
请给我一个参考网站的例子,以得到清晰的想法。我仍然对此感到困惑
res = cr.dictfetchall()
res2 = cr.dictfetchone()
res3 = cr.fetchall()
res4 = cr.fetchone()
cr 是数据库游标中的当前行 (OPENERP 7 )
ex :
def _max_reg_no(self, cr, uid, context=None):
cr.execute("""
select register_no as reg_no
from bpl_worker
where id in (select max(id) from bpl_worker)
""")
res = cr.fetchone()[0]
print (res)
return res
cr.dictfetchall()
将以**字典列表**的形式为您提供所有匹配记录,其中包含核心价值.
cr.dictfetchone()
工作方式与cr.dictfetchall()
除非它只返回单个记录。
cr.fetchall()
将为您提供所有匹配记录的形式元组列表.
cr.fetchone()
工作方式与cr.fetchall()
除非它只返回单个记录。
在您给定的查询中,如果您使用:
-
cr.dictfetchall()
会给你[{'reg_no': 123},{'reg_no': 543},]
.
-
cr.dictfetchone()
会给你{'reg_no': 123}
.
-
cr.fetchall()
会给你'[(123),(543)]'。
-
cr.fetchone()
会给你'(123)'。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)