1 import psycopg2
 2 
 3 class XXXXX(models.Model):
 4         ........
 5 
 6     @api.multi
 7     def OOOO(self):
 8         db = psycopg2.connect("dbname=test4 user=postgres")#查找名叫 test4 的数据库  postgres  是数据库的超级用户名称
 9         vals = db.cursor()
10         vals.execute("SELECT sales,prices,sale_date FROM run_chart")#执行sql语句查询数据
11         tables = vals.fetchall()#返回查询结果

此代码用的数据库为:postgresql

 

odoo 还有另外一种更加方便的SQL查询方式

例子:

sql = "select *from 表名"
self.env.cr.execute(sql)  #执行SQL语句
dicts = self.env.cr.dictfetchall()  #获取SQL的查询结果

 

相关文章:

  • 2021-12-04
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2021-08-09
  • 2022-01-07
  • 2021-10-09
  • 2021-10-06
相关资源
相似解决方案