I want to check if the ID exists already but I get this error:
Not all parameters were used in the SQL statement
Code:
Id = "TEST" sql = """SELECT * FROM musics WHERE Id = %s""" dbc.execute(sql, Id) row = cursor.rowcount if row == 0: #NOT EXSIST
Advertisement
Answer
The second argument to execute()
should be a sequence of values, one for each placeholder token %s
in the query.
You did pass a sequence, but not in the way you intended. Strings are sequences, so you actually passed a sequence of four values – T, E, S, T
, which is too many values, because the query only has one placeholder token.
Pass the string as a one-element tuple, like so:
args = ("TEST",) sql = """SELECT * FROM musics WHERE Id = %s""" dbc.execute(sql, args)