I am trying to make a method which will allow me to edit existing data in an SQLite3 database. The relevant part of the code which throws an error is this:
self.chosen = "Example_column" # Column reference
self.edited = "Something" # Replacement value for chosen/chooseAccount reference
self.chooseAccount = 1 # Primary key, in column called "ID"
self.sql = "UPDATE Accounts_CV SET ?=? WHERE ID=?;"
c.execute(sql, (self.chosen, self.edited, self.chooseAccount,))
c.commit()
I get the following traceback:
Traceback (most recent call last):
File "/Users/johntamm-buckle/Documents/python scripts/accounts/cv_main.py", line 44, in <module>
mainLoop()
File "/Users/johntamm-buckle/Documents/python scripts/accounts/cv_main.py", line 24, in mainLoop
db.editEntry()
File "/Users/johntamm-buckle/Documents/python scripts/accounts/db_handler/db_handler.py", line 125, in editEntry
c.execute(self.sql, (self.chosen, self.edited, self.chooseAccount,))
sqlite3.OperationalError: near "?": syntax error
Am I not able to assign the field reference to a ? placeholder? If not, what is the recommended way to edit a specific ID/field reference, where both the ID and field reference are dynamic?