Skip to Content
Menu
This question has been flagged
3 Replies
10899 Views

How to execute SQL code into Python Code?


SELECT  RiskID.RiskID,  RiskID.FuncID1,  FUNCID.TCODE FROM   RiskID INNER JOIN  FUNCID ON  RiskID.FuncID1 =  FUNCID.FUNCID

Avatar
Discard
Best Answer

Hello, 
You can try below code maybe it helps you 

query = """(SELECT  RiskID.RiskID,  RiskID.FuncID1,  FUNCID.TCODE FROM   RiskID INNER JOIN  FUNCID ON  RiskID.FuncID1 =  FUNCID.FUNCID)"""
cr = self._cr
cr.execute(query)

Thanks 

Avatar
Discard
Best Answer

Use below mentioned code: sql = """select count(name) from table_name where lower(field_name) = lower('%s') """ % self.field_name self.env.cr.execute(sql)

Avatar
Discard
Best Answer

Hello 

use self._cr.execute() to execute your sql query.

for eg. self._cr.execute("""SELECT  RiskID.RiskID,  RiskID.FuncID1,  FUNCID.TCODE FROM   RiskID INNER JOIN  FUNCID ON  RiskID.FuncID1 =  FUNCID.FUNCID """)

then you can get your result using below code:

result = self._cr.dictfetchall() or   result = self._cr.fetchall()

Avatar
Discard