Skip to content Skip to sidebar Skip to footer

Python Sqlite3 Operationalerror: Near "?": Syntax Error

Trying to let users update column values on existing records for a specific table named 'Scenario.' The record being updated is identified by an index column called 'Scenario_Key'

Solution 1:

You cannot parametrize column names. While being cognisant of the possibility of SQL Injection attacks, you could instead do:

cursor.execute("""UPDATE Scenario 
                     SET {}=? 
                   WHERE Scenario_Key=?;""".format(key), 
               (new_val, self.scenario_key))

Post a Comment for "Python Sqlite3 Operationalerror: Near "?": Syntax Error"