将字段名称变量分配给"?"时出现语法错误占位符

时间:2015-10-09 13:31:37

标签: python python-3.x sqlite syntax-error

我正在尝试创建一个方法,允许我编辑SQLite3数据库中的现有数据。抛出错误的代码的相关部分是:

    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()

我得到以下追溯:

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

我无法将字段引用分配给?占位符吗?如果没有,编辑特定ID /字段引用的建议方法是什么,其中ID和字段引用都是动态的?

0 个答案:

没有答案