我正在运行下面的代码段,以在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
与查询相关的问题是什么?
发布于 2014-08-06 05:31:58
当前,tuple(prev_open_fiscalyear_ids)
被解释为在查询中替换的参数列表。这不是你的意思,你想让你的元组代替一个论点:
cr.execute(query, (tuple(prev_open_fiscalyear_ids),))
除非我错过了什么,否则这也会奏效的:
cr.execute(query, (prev_open_fiscalyear_ids,))
最后,逗号是因为(x)
始终与x
相同,而(x,)
是带有单个元素的元组。
https://stackoverflow.com/questions/25152640
复制相似问题