繁体   English   中英

pysqlite不接受qmark参数化

[英]pysqlite not accepting qmark parameterization

我有一个与Python pysqlite中已回答的问题类似的问题,但不接受我的qmark参数化

我的问题如下:我想要参数化搜索类似字符串的字符串,而不是字符串本身。

这是我的声明:

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被解释为文字。 但是,我不知道如何在不将qmark解释为文字的情况下指定此类“ like”搜索和qmark。

以下搜索成功:

command = "select id, l from testDT where l like '%, {x}]' "
command = command.format(x=123)
cur.execute(command)

但是,据我了解,这正是一个不应使用格式()函数的方式。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM