Reputation: 131
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." 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
I misrepresented my parameters. I used the qmarks notation mentioned in the accepted answer below to reference table rows
Upvotes: 0
Views: 2241
Reputation: 180070
The documentation says:
The
sqlite3
module supports two kinds of placeholders: question marks (qmark style) and named placeholders (named style).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):
db.execute("SELECT ... :username", dict(username = username))
Upvotes: 3