openerp:在where子句中使用变量的值

时间:2013-10-28 12:44:27

标签: sql postgresql openerp

abe= []
abibiti=1
self.cr.execute("SELECT name FROM account_analytic_account where parent_id=abibiti")                
for t in self.cr.fetchall():
for item in t:
    abe.append(item)

我想使用变量“abibiti”的值来检查where子句,任何人都可以帮助我

1 个答案:

答案 0 :(得分:2)

在cr.execute中编写查询的方式存在一些问题。请将其更改为:

abe= []
abibiti=1
cr.execute("SELECT name FROM account_analytic_account where parent_id=%s"%(abibiti))                
for t in cr.fetchall():
    for item in t:
        abe.append(item)