Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sqlite3.2错误:无法识别的令牌:“0”;{quot;_Python_Mysql_Sql_Sqlite - Fatal编程技术网

Python sqlite3.2错误:无法识别的令牌:“0”;{quot;

Python sqlite3.2错误:无法识别的令牌:“0”;{quot;,python,mysql,sql,sqlite,Python,Mysql,Sql,Sqlite,首先,我知道这里已经有类似标题的帖子,我已经看过了这些问题的答案,但仍然无法从这些答案中找到解决方案(我的问题与其他问题略有不同) 我需要能够更新sqlite数据库中特定记录的字段值 我在这里的代码中使用了相同的格式: updateCustomerTable = c.execute("UPDATE customerTable SET {} = ? WHERE customerID = ?").format(age), (newAge.get(),) , (customerID.get(),)

首先,我知道这里已经有类似标题的帖子,我已经看过了这些问题的答案,但仍然无法从这些答案中找到解决方案(我的问题与其他问题略有不同)

我需要能够更新sqlite数据库中特定记录的字段值

我在这里的代码中使用了相同的格式:

updateCustomerTable = c.execute("UPDATE customerTable SET {} = ? WHERE customerID = ?").format(age), (newAge.get(),) , (customerID.get(),)
但我收到一条错误消息:

sqlite3.OperationalError: unrecognized token: "{"
为什么当开发人员在另一篇文章的答案中使用了花括号时,不允许使用花括号?

这里(为了可读性而重新格式化代码):

因此,实际上您是在对
c.execute()
的结果调用
.format()
,而不是在SQL查询字符串上。如果查询是有效的SQL FWIW,它实际上会引发一个
AttributeError

你想要的是:

sql = "UPDATE customerTable SET {} = ? WHERE customerID = ?".format(age)  
c.execute(sql, ...)

我已经将检索结果的参数放在了执行行中,所以c.execute(sql,(newAge.get(),),(customerID.get(),)但是这意味着有3个参数,其中有2个参数?我应该在该行中放一些其他参数吗?这个问题解决了吗?如前所述,
.format()
方法必须在字符串语句上操作,查询参数作为列表或元组在一个附加参数中传递。
sql = "UPDATE customerTable SET {} = ? WHERE customerID = ?".format(age)  
c.execute(sql, ...)