skip to Main Content

I am trying to use a input variable into a SELECT statement but getting the error below.

Here is my code:

sheetname=input("Enter the name of the SEO Analysis sheet:")
cur=conn.execute("select * from seo_info where url like '%?%'",sheetname,)
print(cur.fetchall())

and here is an error:

File "E:/Python/SEO_Project2.py", line 40, in <module>
cur=conn.execute("select * from seo_info where url like '%?%'",sheetname,)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 9 supplied.

Here is another question, that addresses a part of the issue, but still it is giving me error.

Maybe I am missing a little something in my code?

2

Answers


  1. Chosen as BEST ANSWER

    I did it !

    cur=conn.execute("select * from seo_info where url like (?)",['%'+sheetname+'%'])
    

  2. You don’t really need parentheses around ?, so you can achieve what you want using list, as a second argument to execute:

    cur = conn.execute('SELECT * FROM seo_info WHERE url LIKE ?', ['%' + sheetname + '%'])
    

    or tuple:

    cur = conn.execute('SELECT * FROM seo_info WHERE url LIKE ?', ('%' + sheetname + '%'),)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search