我有这段代码:
Title= "somewords"
itemID = somenumbers
import sqlite3
db = sqlite3.connect('C:\\db.sqlite')
cursor = db.cursor()
cursor.execute('SELECT itemID FROM itemAttachments WHERE path LIKE "%?%" ', (Title, ))
cursor.execute('SELECT key FROM items WHERE itemID =? ', (itemID,))
where item=?
的第二个陈述有效,但第一个有like
的陈述给我带来了麻烦。
我尝试了许多组合,例如"+Title+"
和{} .format(Title)
,添加或删除" %...%"
,但每次收到错误:sqlite3.ProgrammingError: Incorrect number of bindings supplied
或sqlite3.OperationalError: near ",": syntax error
。
答案 0 :(得分:1)
您必须将%
添加到参数:
cursor.execute('SELECT itemID FROM itemAttachments WHERE path LIKE ?', ('%{}%'.format(Title), ))