我正在尝试获取包含数据库中某些数据的网址,但我一直收到此错误:
self = <django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0x7f01c35c2d38>
query = ' SELECT cust.id, cust.name, inv.currency_id, SUM(inv.total)\n FROM\n v3_customer as cust\n ... and inv.invoice_date < ?\n GROUP BY cust.id, inv.currency_id\n ORDER BY cust.id, inv.currency_id'
params = [(1,), '2016-12-04']
def execute(self, query, params=None):
if params is None:
return Database.Cursor.execute(self, query)
query = self.convert_query(query)
> return Database.Cursor.execute(self, query, params)
E sqlite3.OperationalError: near "?": syntax error
../../../environments/tracerenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py:337: OperationalError
这是我的代码:
response = admin_client.post(
reverse('report_create') + '?report_type=1',
{
'start_date': datetime.datetime.now().date() - datetime.timedelta(days=180),
'end_date': datetime.datetime.now().date() + datetime.timedelta(days=180),
}
)
print(admin_client.get(Report.objects.first().get_absolute_url()))
我在这里发现它失败了:
PRE_INV_Q = """\
SELECT cust.id, cust.name, inv.currency_id, SUM(inv.total)
FROM
v3_customer as cust
JOIN v3_customerproxy ON cust.id = v3_customerproxy.original_id
JOIN v3_invoice as inv ON v3_customerproxy.id = inv.customer_id
WHERE
cust.id IN %s
and inv.type = 'i'
and inv.invoice_date < %s
GROUP BY cust.id, inv.currency_id
ORDER BY cust.id, inv.currency_id
答案 0 :(得分:1)
从我所看到的你convert_query
方法只是替换查询中的参数。请尝试使用%s
代替?
。