3

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

davidx1
  • 3,525
  • 9
  • 38
  • 65

1 Answers1

9

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].

kenm
  • 23,127
  • 2
  • 43
  • 62