Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

5

Please define these Python Fetch types [Closed]

By
priyankahdp
on 3/28/13, 7:26 AM 5,479 views

The Question has been closed

by
Sudhir Arya (SA)
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

This question has been included in the official documentation.
20

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 3/28/13, 8:36 AM

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

+1 for nice explanation & great example.

Sasuke
on 3/28/13, 8:38 AM

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

Frank
on 6/18/13, 9:24 AM

Perfect example! Thank you!

Selverine
on 8/31/13, 5:50 AM

Nice expalantion..Thanks

Odoo
on 6/25/14, 6:38 AM
This question has been included in the official documentation.
1
DNTQ
On 3/28/13, 7:38 AM

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

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

thanks DNT :-)

priyankahdp
on 3/28/13, 10:26 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/28/13, 7:26 AM
Seen: 5479 times
Last updated: 9/15/15, 2:55 AM