Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading from database with SQLite and Python: Incorrect number of binding supplied

am reading out of a database with the following python script:

cur.execute("SELECT * FROM pending where user = ?", (ID))

Where ID is someone's name, in this case "Jonathan".

However, when I try to run this script, I get the error saying

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/cherrypy/_cprequest.py", line 606, in respond
    cherrypy.response.body = self.handler()
  File "/usr/lib/pymodules/python2.7/cherrypy/_cpdispatch.py", line 25, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "proj1base.py", line 470, in editFriends
    cur.execute("SELECT * FROM pending where user = ?", (ID))
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 8 supplied.

I am very new to SQLite, so i'm guessing I just made a very silly mistake in syntax. However after searching around online for a while, i can't seem to find anything different that I am doing than others.

Any help would be much appreciated. Or if you need more code, please let me know.

Thanks

like image 351
davidx1 Avatar asked May 23 '26 04:05

davidx1


1 Answers

You must supply a sequence of values for the binding. ID is a string, so it looks like a sequence of 8 values.

You're probably thinking that (ID) should be a tuple with one element, but it isn't. Parenthesis aren't the tuple-making syntax in Python (except for the empty tuple). Commas are. Use (ID,) instead to get a tuple with one element. Alternatively, use a list: [ID].

like image 188
kwatford Avatar answered May 25 '26 17:05

kwatford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!