Community mailing list archives

community@mail.odoo.com

Re: Odoo 8 computed field issue

by
OpusVL, Nick Booker
- 11/20/2015 09:38:02
Hi Yassine.

Yassine Teimi <yteimi01@gmail.com> writes:

> On the other hand, do you have an idea what kind of return does :
> self.env.cr.execute('sql suery') ?

It returns nothing useful.

Do cr.fetchall() to get a list of tuples containing the results.

There's also cr.fetchone() and cr.fetchmany().

See also: http://initd.org/psycopg/docs/usage.html
          http://initd.org/psycopg/docs/cursor.html


>
> And how to use sql query parameters ? explicitly, how to use variables
> on the sql query ?

cr.execute(
    'SELECT x, y, z FROM table WHERE name = %s AND state = %s',
    (myname, mystate)
)

for x, y, z in cr.fetchall():
    # do something with x, y and z