Python Forum

Full Version: select one item from row with sqlite3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a database consisting of 3 columns. I want to match just one item from one column.

def interface():
    '''Create interface allowing team members to bid starting with highest seniority.'''
    # Enter name
    name = input('Enter your name. ')

    # confirm name and current bid
    conn = sqlite3.connect('Bid.db')
    cursor = conn.cursor()
    sql = 'SELECT Name FROM Bid WHERE Name=?'
    results = cursor.execute(sql, name)
    #bid_list = results.fetchall()
    print(results)
    confirm = input(f'Is this you?\n{bid_list}\n')
    options = ('1 Yes', '2 No')
    print('\n'.join(options))
current output:
Enter your name. bob
Error:
Traceback (most recent call last): File "interface.py", line 35, in <module> interface() File "interface.py", line 18, in interface results = cursor.execute(sql, name) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied.
desired output:

Enter your name. bob
is this you? bob
1 Yes
2 No

What am I doing wrong?
cursor.execute is expecting a sequence for the second parameter. A sting is a sequence, so it tried to match 'b', 'o', and 'b' to the sql code. Try results = cursor.execute(sql, [name]) instead.