Python pysqlite不接受qmark参数化

Python pysqlite不接受qmark参数化,python,pysqlite,parameterization,Python,Pysqlite,Parameterization,我有一个类似的问题,而不是在 我的问题如下: 我想要一个参数化的字符串搜索,它类似于某种东西,而不是字符串本身 我的声明如下: command = "select id, l from testDT where l like '%, ?]'" cur.command(command, (123,)) pysqlite返回以下错误: pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The cur

我有一个类似的问题,而不是在

我的问题如下: 我想要一个参数化的字符串搜索,它类似于某种东西,而不是字符串本身

我的声明如下:

command = "select id, l from testDT where l like '%, ?]'"
cur.command(command, (123,))
pysqlite返回以下错误:

pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current     statement uses 0, and there are 1 supplied.
我理解这是因为qmark被解释为一个文本。但是,我不知道如何使用qmarks指定这样的“like”搜索,而不将qmarks解释为文本

以下搜索成功:

command = "select id, l from testDT where l like '%, {x}]' "
command = command.format(x=123)
cur.execute(command)
但是,据我所知,这正是不应该使用format()函数的方式。

您使用整个批次作为参数,例如:

command = "select id, l from testDT where l like ? "
cur.command(command, ('%, 123]',))

谢谢工作起来很有魅力!也许还有一个问题:这种方法安全吗?x=123 command=“从testDT中选择id,l,我喜欢什么?”cur.command(command,('%,{}]')。format(x),)@user142295 yes。。。只要不将格式应用于SQL查询本身,就可以应用格式来构建参数,并且该参数将在实际查询中正确转义。