在sqlite3中使用具有多个条件的LIKE

时间:2018-03-28 14:05:47

标签: python sqlite

我正在使用python 2.7并尝试将LIKE方法与sqlite3

一起使用
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]

1 个答案:

答案 0 :(得分:0)

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