Reputation: 54
My code:
name1 = name_entry.get()
conn = sqlite3.connect('test123.db')
c = conn.cursor()
c.execute("SELECT * FROM table123 WHERE name = name1")
print(c.fetchall())
conn.commit()
conn.close()
Error:
sqlite3.OperationalError: no such column: name1
My question How do I use a variable with WHERE caluse to find the desired tuples ?
Upvotes: 0
Views: 29
Reputation: 34046
You should substitute the variable name1
value in your c.execute
statement. Do this:
c.execute("SELECT * FROM table123 WHERE name = {}".format(name1))
OR:
c.execute("SELECT * FROM table123 WHERE name = ?", name1)
Upvotes: 1