I'm resorting to overflow as a last ditch effort. I have been facing this bug for an incredibly long time and I have had no luck. I will try anything.
My sql command is
update_query = """
UPDATE users_data
SET stocks = """+str(stock)+"""
WHERE id = """+str(userid)
cursor = connection.cursor(buffered=True)
cursor.execute(update_query)
connection.commit()
context: the variable stock is a list before I use str() on it. userid is an int before I use str() on it. the column stocks has a datatype of mediumtext the column id has a datatype of text
the error I receive is
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 '['gme', '1'] WHERE id = 407081272293326858' at line 2
Please help
-
You should use a format string or another approach to your query as this approach is vulnerable to sql injections.Ryan Deschamps– Ryan Deschamps2021年01月21日 14:17:31 +00:00Commented Jan 21, 2021 at 14:17
-
See stackoverflow.com/a/9433548/3050664.Ryan Deschamps– Ryan Deschamps2021年01月21日 14:24:27 +00:00Commented Jan 21, 2021 at 14:24
-
2Learn to use parameters!Gordon Linoff– Gordon Linoff2021年01月21日 14:33:31 +00:00Commented Jan 21, 2021 at 14:33