I am trying to use placeholders, but they do not work. Here is a bad example of what i need, it works perfectly, but it is not protected against SQL-injections:
`def updateUser(self, user_id: int, **kwargs) -> bool:
for arg, value in kwargs.items():
try:
sql = f"UPDATE user SET {arg}='{value}' WHERE user_id = {user_id};"
self.con.execute(sql)
except Exception as e:
print(e)
self.con.rollback()
return False
self.con.commit()
return True
`
It works with any data type perfectly. Now the code that i want to use, but it don't work:
`def updateUser(self, user_id: int, **kwargs) -> bool:
for arg, value in kwargs.items():
try:
self.con.execute("UPDATE user SET ?='?' WHERE user_id = ?;", (arg, value, user_id))
except Exception as e:
print(e)
self.con.rollback()
return False
self.con.commit()
return True
` This code returns error:
`>>> ud.updateUser(1, nick="test")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<path>/inter.py", line 56, in updateUser
self.con.execute("UPDATE user SET ?='?' WHERE user_id = ?;", (arg, value, user_id))
sqlite3.OperationalError: near "?": syntax error
`
I've tried every possible way to write this query (brackets, quotes), but it only works with f-string. What am i doing worng?