Please explain these types of Python Fetch.

What is the difference between these samples? please give me examples for the link site to get a clear view. Until I get embarrassed with him.

res = cr.dictfetchall()

res2 = cr.dictfetchone()

res3 = cr.fetchall()

res4 = cr.fetchone()

cr - current row, from database cursor (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
+5
source share
1 answer

cr.dictfetchall()will provide you with all the relevant entries in the form of a ** dictionary list ** containing the key , value .

cr.dictfetchone()works the same as cr.dictfetchall()except that it returns only one record.

cr.fetchall()will provide you with all relevant entries in the form of a tupple list .

cr.fetchone()works the same as cr.fetchall()except that it returns only one record.

In your request, if you use:

  • cr.dictfetchall()will provide you [{'reg_no': 123},{'reg_no': 543},].
  • cr.dictfetchone()will provide you {'reg_no': 123}.
  • cr.fetchall() will give you "[(123), (543)]."
  • cr.fetchone() will give you "(123)".
+16
source

All Articles