Gabriel Mulcahy
Gabriel Mulcahy

Reputation: 19

Select sqlite3 row by second column

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?

Table

Upvotes: 0

Views: 380

Answers (1)

Rafiul Sabbir
Rafiul Sabbir

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

Related Questions