2016-11-23 213 views
0

进口的sqlite3我有这样的代码:与其中var LIKE语句

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让我烦恼。

我已经尝试了许多combinaisons像"+Title+"{} .format(Title),添加或删除“%...%"但每次我得到一个错误:要么sqlite3.ProgrammingError: Incorrect number of bindings suppliedsqlite3.OperationalError: near ",": syntax error

回答

1

你必须在%添加到参数:

cursor.execute('SELECT itemID FROM itemAttachments WHERE path LIKE ?', ('%{}%'.format(Title),))