What is the difference between these fetching.? please give me a examples for reference site to get clear idea.still i'm confuse with it
res = cr.dictfetchall()
res2 = cr.dictfetchone()
res3 = cr.fetchall()
res4 = cr.fetchone()
cr is the current row, from the 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
cr.dictfetchall()
will give you all the matching records in the form of ** list of dictionary** containing key, value.
cr.dictfetchone()
works same way as cr.dictfetchall()
except it returns only single record.
cr.fetchall()
will give you all the matching records in the form of list of tupple.
cr.fetchone()
works same way as cr.fetchall()
except it returns only single record.
In your given query, if you use:
cr.dictfetchall()
will give you [{'reg_no': 123},{'reg_no': 543},]
.cr.dictfetchone()
will give you {'reg_no': 123}
.cr.fetchall()
will give you '[(123),(543)]'.cr.fetchone()
will give you '(123)'.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With