Following this example I am attempting to rewrite code that works with code that protects against SQL injection:
Code that works:
table = "led_status"
field = "test_led"
value = "FALSE"
cursor.execute(("UPDATE %s SET %s = %s") % (table, field, value))
code that does not work:
table = "led_status"
field = "test_led"
value = "FALSE"
cursor.execute(("UPDATE %s SET %s = %s", table, field, value))
Nor does this code work:
table = "led_status"
field = "test_led"
value = "FALSE"
sql_update_command = "UPDATE %s SET %s = %s"
cursor.execute(sql_update_command, (table, field, value))
The first example works, the others do not and each of them throw this syntax error:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''led_status' SET 'test_led' = 'FALSE'' at line 1
I am not sure what I am doing wrong so any pointers would be greatly appreciated.