Python Forum
select one item from row with sqlite3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
select one item from row with sqlite3
#1
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?
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove an item from a list contained in another item in python CompleteNewb 19 5,661 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Select correct item from list for subprocess command pythonnewbie138 6 3,285 Jul-24-2020, 09:09 PM
Last Post: pythonnewbie138
  Python3 and sqlite3 using AND with SELECT darktitan 6 3,776 Mar-01-2019, 04:33 PM
Last Post: darktitan
  SQL select join operation in python(Select.. join) pradeepkumarbe 1 2,230 Feb-14-2019, 08:34 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020