'Why does SQLite3 tell me that I supplied N > 1 bindings when trying to pass a single string as placeholder value?

I am new in SQLite and I need help in this one. I am trying to make a simple function in python that takes a database name and table name and make it display the whole table. I wrote it like this:

def columnlist(dbname, tablename):
    dbname = str(dbname)
    tablename = str(tablename)
    conn = sqlite3.connect(dbname)
    c = conn.cursor()
    c.execute('SELECT sql FROM sqlite_master WHERE type=\'table\' AND name=?', tablename)
    pp.pprint(c.fetchall())
    conn.close()

When I passed the string 'students' as tablename, it gave me the following error:

File "C:/Users/XXXX/Documents/Python Scripts/Assignment 3/L6Q1.py", line 20, in columnlist
    c.execute('SELECT sql FROM sqlite_master WHERE type=\'table\' AND name=(?)', str(tablename))

ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 8 supplied.

What did I do wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source