Reputation: 19
I'm using a small python program to query an sqlite3 database of ingredients and recipes.
I want to find out how much of a certain ingredient I have by searching it by name.
I'm currently using:
cursor.execute('SELECT amount FROM Ingredients WHERE ingredient_name = Pasta')
When I run the program I get 'no such column: Pasta'
. It works when I search by the id instead. How can I solve this?
Upvotes: 0
Views: 380
Reputation: 636
The good way of executing a query is as follows:
cursor.execute(QUERY, params)
So you can do the following:
QUERY = "SELECT amount FROM Ingredients WHERE ingredient_name = ?"
cursor.execute(QUERY, ('Pasta',))
Upvotes: 1