Odoo的游标cr获取结果fetchall等分析

来源:互联网 发布:大连软件职业学校 编辑:程序博客网 时间:2024/06/05 06:15




详解:

cr.dictfetchall() will give you all the matching records in the form of the list of dictionary containing key, value [{'': ''}, {'': ''}, ...].

cr.dictfetchone() works same as cr.dictfetchall() except it returns only a single record {'': ''}.

cr.fetchall() will give you all the matching records in the form of the list of tuple [(''), (''), ...].

cr.fetchone() works same way as cr.fetchall() except it returns only single record ('').

========================================================================

简要解释:

cr.dictfetchone return {'key':value.....} 

cr.dictfetchall return [{'key':value.....},{'key':value.....}]

cr.fetchone return [value,value...] 

cr.fetchall return [[value,value],[value,value]]

========================================================================

例子:

In your given query, the output would be as follow:

  1. cr.dictfetchall() will give you [{'reg_no': 123},{'reg_no': 543},].
  2. cr.dictfetchone() will give you {'reg_no': 123}.
  3. cr.fetchall() will give you '[(123),(543)]'.
  4. cr.fetchone() will give you '(123)'.

原创粉丝点击