[英]Python error trying to use .execute() SQLite API query With keyword arguments
I'm learning SQLite and have been trying to create a string that stores values and retrieves rows, but I get an error "execute() takes no keyword arguments." 我正在学习SQLite,并一直试图创建一个存储值并检索行的字符串,但出现错误“ execute()不包含关键字参数”。 This is the way I referenced the database:
这是我引用数据库的方式:
import sqlite3
dbb = sqlite3.connect('finance.db')
db = dbb.cursor()
username = request.form.get("username")
#query database for username
rows = db.execute("SELECT * FROM users WHERE username = :username", \
username=username)
UPDATE UPDATE
I misrepresented my parameters. 我弄错了我的参数。 I used the qmarks notation mentioned in the accepted answer below to reference table rows
我将下面接受的答案中提到的qmarks符号用于引用表行
The documentation says: 该文件说:
The
sqlite3
module supports two kinds of placeholders: question marks (qmark style) and named placeholders (named style).sqlite3
模块支持两种占位符:问号(qmark样式)和命名占位符(命名样式)。Here's an example of both styles:
这是两种样式的示例:
# This is the qmark style: cur.execute("insert into people values (?, ?)", (who, age)) # And this is the named style: cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
Keyword arguments are not supported. 不支持关键字参数。 However, you could explicitly convert them into a dictionary (or write a wrapper for
execute
that does this): 但是,您可以将它们显式转换为字典(或为
execute
此操作的execute
编写包装器):
db.execute("SELECT ... :username", dict(username = username))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.