2017-10-06 169 views
0

试图对一个sqlite3的数据库执行光标查询时,我收到以下错误消息: enter image description here为什么Django connection.cursor查询失败?

我的代码如下:在cursor.execute线发生

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() 

错误。 日期是包含该值2017年10月5日

另外一个字符串,则该参数放入查询django的内或正在传递给SQLite的(即应该我参数占位符是%S或?)?

谢谢!

+0

'%s'应该可以解决你的问题。你试过了吗? –

+0

感谢您的建议,但是%s会导致以下错误:/balancer/set_security_prices处的ProgrammingError/2017-10-05 提供的绑定数量不正确。当前语句使用0,并提供1。 – Ben

+1

你在做这个''%s''或这个'%s'。使用它没有引号 –

回答

1

只需使用它而不用引号。将"%s"更改为%s