Reading from database using SQLite and Python: wrong number of bindings

Reading a database with the following python script:

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

      

If the identifier is the name of someone, in this case "Jonathan".

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

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'm very new to SQLite, so I guess I just made a very stupid mistake in the syntax. However, after searching the internet for a while, I cannot find anything else that I am doing than others.

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

thank

+3


source to share


1 answer


You must provide a sequence of values ​​to bind. ID

is a string, so it looks like a sequence of 8 values.



You are probably thinking that it (ID)

should be a tuple with one element, but it is not. Parenthesis is not a tuple syntax in Python (except for an empty tuple). Commas. Use (ID,)

instead to get a single element tuple. Also, use the list: [ID]

.

+9


source







All Articles