Hello everybody i am Trying to do a Update statment with the python mysql connector but i allways get the error
mysql.connector.errors.ProgrammingError: Could not process parameters: int(633671912411), it must be of type list, tuple or dict
i have tryed with oder binding types but this also dont work
i dont have a clue why i get this error .
Code:
cursor.execute("""Update users set CARDSN = :id where Username = :username """, id,username)
CodePudding user response:
Please do not use reserved names or functions like id()
for variable names. Use specific names like user_id
As the error says: Arguments must be supplied list, tuple or dict, not one by one. Since you specify keyword arguments, you need a dict
:
cursor.execute("""Update users set CARDSN = :id where Username = :username """, {'id': id, 'username': username})
CodePudding user response:
As the error message is telling you, your data "must be of type list, tuple or dict".
If you look at this example, the data
variable is a tuple.
#The SQL statement, don't mind it
insert_stmt = (
"INSERT INTO employees (emp_no, first_name, last_name, hire_date) "
"VALUES (%s, %s, %s, %s)"
)
# Here data is a TUPLE of 4 elements
data = (2, 'Jane', 'Doe', datetime.date(2012, 3, 23))
cursor.execute(insert_stmt, data)
In your case, you probably just need to put the parenthesis around id, username
.
What you are currently doing is calling the function execute
with 3 parameters : Your SQL statement, the variable id
AND the variable username
. The framework is waiting for 2 parameters : the statement and the data. You need to put your id and username inside one single variable, that is a tuple, dict or list.
This could be :
my_dict = {'id': id, 'username': username}
cursor.execute(statement, my_dict)
Or if you don't want intermediate variables :
cursor.execute("""Update users set CARDSN = :id where Username = :username """, {'id': id, 'username': username})