小编atc*_*uno的帖子

在LIKE中使用通配符替换Python SQLite参数

我试图使用Python的Sqlite库进行参数化LIKE查询,如下所示:

self.cursor.execute("select string from stringtable where string like '%?%' and type = ?", (searchstr,type))
Run Code Online (Sandbox Code Playgroud)

但是?没有评估通配符内部,但是我发现此错误:

"sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied."
Run Code Online (Sandbox Code Playgroud)

我还尝试使用标记版本的查询:

like '%:searchstr%' 并在列表中 {"searchstr":searchstr...

但是,当我这样做时,查询运行但从不返回任何结果,即使手动"like '%a%'"...返回数百个结果应该

有什么建议吗?

python sqlite sql-like

35
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

sql-like ×1

sqlite ×1