0

我有一个与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 解释为文字的情况下使用 qmark 指定这样的“like”搜索。

以下搜索成功:

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

但是,据我了解,这正是应该使用 format() 函数的方式。

4

1 回答 1

1

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

command = "select id, l from testDT where l like ? "
cur.command(command, ('%, 123]',))
于 2014-03-07T11:50:16.213 回答