简体   繁体   English

尝试使用带有关键字参数的.execute()SQLite API查询的Python错误

[英]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.

相关问题 尝试使用 eval() 在 Python 中获取关键字 arguments 时出现语法错误 - SyntaxError while trying to use eval() to get keyword arguments in Python 得到错误 TypeError: execute() 没有关键字 arguments - Got the error TypeError: execute() takes no keyword arguments Python试图在* args之后放置关键字参数 - Python trying to place keyword arguments after *args Python和Sqlite:由于语法错误,无法执行查询 - Python & Sqlite: Can't execute query due to a syntax error 如何在参数中使用带有关键字“self”的Python函数 - how to use a Python function with keyword “self” in arguments 在Python函数参数中使用表达式作为关键字 - Use an expression as keyword in python function arguments 尝试在 Python 中执行此 SQL 查询时出现语法错误 - Getting a syntax error when trying to execute this SQL query in Python python3.5 import tensorflow.contrib错误:函数具有仅关键字的参数或注释,请使用可以支持它们的getfullargspec()API - python3.5 import tensorflow.contrib error: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them 尝试将 sqlite 与 python shell 一起使用 - Trying to use sqlite with python shell 在 sqlite 值中使用查询 - python - Use a query in sqlite value - python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM