函数如何在odoo 9中创建sql语句?
我要打电话给my_function,从数据库打印所有记录。
例如:从“时间”中选择“time_start”,其中time_start >=“当前”
def my_function(self):
result = []
for data in self.browse():
cr.execute('''select
time_start
from
time
where
time_start >= 'TODAY''')
print all result line by line发布于 2016-12-19 16:22:46
试一试
def my_function(self):
result = []
for data in self.browse():
cr.execute('''select
time_start
from
time
where
time_start >= 'TODAY''')
for line in cr.dictfetchall():
print line["time_start"]
print linecr.dictfetchall()返回一个dicts列表。此列表中的每个元素都表示查询结果中的一行。
在我的解决方案中,我迭代这个列表,并可以通过数据库中的字段名直接访问该字段。
请注意,在循环中使用查询。也许还有更好的办法。
编辑:尝试search而不是browse。browse为您提供与给定ids匹配的记录。
def my_function(self):
result = []
for data in self.search([]):
cr.execute('''select
time_start
from
time
where
time_start >= 'TODAY''')
for line in cr.dictfetchall():
print line["time_start"]
print linehttps://stackoverflow.com/questions/41225365
复制相似问题