我正在运行以下代码段,以在jasper
OpenERP
报告
prev_open_fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft'), ('date_start', '<', fiscal_date_start)]) # prev_open_fiscalyear_ids gets a list of numbers from this code
cr.execute("SELECT id \
FROM account_period \
WHERE fiscalyear_id IN %s" , (tuple(prev_open_fiscalyear_ids)))
prev_period_ids = filter(None, map(lambda x:x[0], cr.fetchall()))
其中cr
是PostgreSQL
db的数据库游标,我收到以下错误:
,服务器日志为
[2014-08-06 10:27:47,625][ASCO_ERP] ERROR:web-services:[01]: Exception: not all arguments converted during string formatting
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[02]: Traceback (most recent call last):
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[03]: File "/home/zbeanz/workspace/KIAK/service/web_services.py", line 724, in go
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[04]: (result, format) = obj.create(cr, uid, ids, datas, context)
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[05]: File "/home/zbeanz/workspace/KIAK/addons/jasper_reports/jasper_report.py", line 287, in create
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[06]: data['records'] = d.get( 'records', [] )
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[07]: File "/home/zbeanz/workspace/KIAK/addons/kiak_tb_report/JasperDataParser.py", line 53, in get
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[08]: self.generate_records(self.cr, self.uid, self.ids, self.data, self.context) or default_value
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[09]: File "/home/zbeanz/workspace/KIAK/addons/kiak_tb_report/report/trial_balance_report.py", line 149, in generate_records
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[10]: WHERE fiscalyear_id IN %s" % (tuple(prev_open_fiscalyear_ids)))
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[11]: TypeError: not all arguments converted during string formatting
与查询相关的问题是什么
答案 0 :(得分:2)
当前tuple(prev_open_fiscalyear_ids)
被解释为要在查询中替换的参数列表。这不是你的意思,你希望你的元组能够取代单一的论点:
cr.execute(query, (tuple(prev_open_fiscalyear_ids),))
除非我遗漏了某些内容,否则这也应该有效:
cr.execute(query, (prev_open_fiscalyear_ids,))
最后的逗号是因为(x)
始终与x
相同,而(x,)
是具有单个元素的元组。