0

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

1 Answer 1

3

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))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I missed that bit. The qmark style works perfectly for a method of templating I hadn't yet considered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.