【问题标题】:Using LIKE in sqlite3 with more than one condition [duplicate]在具有多个条件的 sqlite3 中使用 LIKE [重复]
【发布时间】:2018-03-28 14:05:47
【问题描述】:

我正在使用 python 2.7 并尝试使用带有 sqlite3 的 LIKE 方法

search1 = self.lineEdit.text()
search = unicode(search1)
conn = sqlite3.connect('storage/container.db')
c = conn.cursor()
c.execute("SELECT * FROM reports WHERE LIKE('؟%',outIn)=1 OR LIKE('؟%',itemName)=1 OR LIKE('؟%',itemUser)=1", (search, search, search, ))

给我一​​个错误:

Traceback (most recent call last):
  File "C:\python\townoftechwarehouse\reports.py", line 67, in create_report
    c.execute("SELECT * FROM reports WHERE LIKE('؟%',outIn)=1 OR LIKE('؟%',itemName)=1 OR LIKE('؟%',itemUser)=1", (search, search, search, ))
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 3 supplied.
[Finished in 18.2s]

【问题讨论】:

  • "؟"不是“?”。
  • 这里已经给出了答案link

标签: python sqlite


【解决方案1】:

As documented here,sqlite3 的正确占位符是 '?',而不是 '%s'。

【讨论】:

    猜你喜欢
    • 2012-10-09
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 2021-09-23
    相关资源
    最近更新 更多