以下工作:
>>> cursor.execute("select * from sqlitetable where rowid in (2,3);")
以下情况没有:
>>> cursor.execute("select * from sqlitetable where rowid in (?) ", [[2,3]] )
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
有没有一种方法可以传入python列表,而不必先将其格式化为字符串?
如前所述,SQLite本机只支持有限的类型集。
要将其他Python类型与SQLite一起使用,必须使它们适应sqlite3模块支持的SQLite类型之一:NoneType、int、float、str、bytes。
https://docs.python.org/3.6/library/sqlite3.html#using-adapters-to-store-additional-python-types-in-sqlite-databases
在Python3.6中,还可以使用f字符串构建查询:
不幸的是没有。每个值都必须有自己的参数标记(
?
)。 由于参数列表可能具有任意长度,因此必须使用字符串格式来生成正确数量的参数标记。幸运的是,这并不难:相关问题 更多 >
编程相关推荐