Help

Please define these Python Fetch types

Closed
Avatar
priyankahdp

The question has been closed

by
Sudhir Arya (ERP Harbor Consulting Services)
on 04/18/2013 04:47:25

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()

as per below answers this is dictionary

[{'selected_tea_workers_line_ids': 3}, {'selected_tea_workers_line_ids': 5}]

then how to return value from that.?

    return {'value': {
                      'selected_tea_workers_line_ids':? ? ?
                      }}

refer this

Avatar
Discard
2 Answers
25

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 ('').


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)'.
4 Comments
Avatar
Discard
Avatar
Sasuke
-

+1 for nice explanation & great example.

Avatar
Frank
-

Really great answer, thank you very much for your effort.

Avatar
Selverine
-

Perfect example! Thank you!

Avatar
Odoo
-

Nice expalantion..Thanks

1
Avatar
DNTQ
Best Answer

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

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

1 Comment
Avatar
Discard
Avatar
priyankahdp
-

thanks DNT :-)