I need to make SQL Query in Openerp with another user than postgres from python code that has only SELECT privileges. Is there a way that cursor(cr) receives connection string?
Asked
Active
Viewed 181 times
-1
-
Why negative? It would be nice if you try to answer the question first... – Tomislav Brabec Mar 07 '16 at 12:42
1 Answers
0
Ok, I found an easy solution for this. As OpenERP uses psycopg as postgres database cursor I have explicitly made an psycopg object with parameters that I need:
conn = psycopg1.connect(database=cr.dbname, user=dbuser, password=dbpass)
cur = conn.cursor()
Be careful, if you want to use dictfetchall you need to import psycopg1:
from psycopg2 import psycopg1
cur.execute(sql)
res = cur.dictfetchall()

Tomislav Brabec
- 529
- 2
- 14
- 20