为什么Django connection.cursor查询失败?

时间:2017-10-06 01:39:44

标签: django django-models

尝试对SQLite3数据库执行游标查询时收到以下错误消息: enter image description here

我的代码如下:

    qry = ('select balancer_security.id, balancer_security.name, balancer_security.symbol, '
           'balancer_securityprice.at_dt, balancer_securityprice.price, balancer_securityprice.notes '
           'from balancer_security LEFT OUTER JOIN balancer_securityprice '
           'ON (balancer_security.id = balancer_securityprice.security_id '
           'AND balancer_securityprice.at_dt="?") '
           # 'AND balancer_securityprice.at_dt="%s") '
           'ORDER BY balancer_security.name')
    from django.db import connection
    cursor = connection.cursor()
    cursor.execute(qry, [date])
    solution = cursor.fetchall()

cursor.execute行发生错误。 date 是一个包含值 2017-10-05

的字符串

此外,参数是在django中放入查询还是传递给SQLite(即我的参数占位符是%s还是?)?

谢谢!

1 个答案:

答案 0 :(得分:1)

只需在没有引号的情况下使用它。将"%s"更改为%s