-1

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?

Tomislav Brabec
  • 529
  • 2
  • 14
  • 20

1 Answers1

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