So I have a table in my Customers.db file that looks like this:
I wanted to make a function which returns the "rows" which has the id equal to the user input. The Table is also called 'Customers and all the columns are type TEXT.
def run_query(db, query, args=NONE):
con = sqlite3.connect(db)
cur = con.cursor()
if args is None:
data = cur.fetchall()
def get_info_by_id(db, ide):
query = "SELECT * FROM Customers WHERE id = ?"
return run_query(db, query, ide)
args argument of
cur.execute needs to be an iterable so that they can be bound to multiple placeholders (
?) if necessary. Therefore you should always be passing a list or tuple.
When you pass a string it gets treated as an iterable of single-character strings, hence it says there were 3 bindings (3 characters in