def update_data(self):
db = sqlite3.connect("SQLite database")
cursor = db.cursor()
cursor.execute("""UPDATE Item SET ? = ? WHERE itemid = ? """,(self.field, self.value, self.ID))
db.commit()
cursor.close()
The error states that there is a syntax error near the "?" but I'm not seeing what the issue is.
Note: This is a method of a class with fully defined attributes.
Many Thanks
The ?
character is not replaced everywhere it appears, only where an expression can be placed. Thus, trying to use ?
for a column name is a sqlite3 syntax error.
You could use
query = 'update Item set {} = ? where itemid = ?'.format(self.field)
cursor.execute(query, (self.value, self.ID))
where, of course, you'd need to scrub self.field
for injection attacks.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments