I'm trying to find a way to select a row in sqlite from Python. Say I have a table soft drinks
with columns drink
and price
, with the primary key being drink name
. I want to select coke
out of drink
name. How would I do this without looping through every single entry?
Here's my code:
conn = sqlite3.Connection("database.db")
curs = conn.cursor()
curs.execute("create table soft drinks (drink name TEXT, drink TEXT, price INTEGER)"
curs.execute("insert into soft drinks (drink name, drink, price) value开发者_开发问答s ("coke", "whatever", 89)")
I'm looking for a command something like curs.execute(select "coke" from soft drinks)
and it will return the whole row.
SQLite uses quotation marks as column identifiers, so you'd need to put quotation marks around the column and table name: SELECT * FROM "soft drinks" WHERE "drink name" = 'Coke';
精彩评论