【发布时间】:2016-03-25 20:31:48
【问题描述】:
我在 mariadb 中有一个名为 Container 的表,其中包含三个字段 container_id、mt_date 和 age 。
我想要做的是,每次加载数据库时,更新/设置与特定 container_id 对应的年龄字段的新值。我将年龄和相应的 container_id 分别保存在 python 字典中作为值和键。比我遍历字典并尝试像这样更新 age -
for i in list(age_dict):
frappe.db.sql("update Container set age = age_dict[i] where container_id = i")
这里,frappe.db.sql() 是我的框架的数据库连接命令。
我不断收到此错误消息-
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[i] where container_id = i' at line 1")
我已经检查了我的 sql 查询代码几次,但找不到语法错误。寻求帮助。
【问题讨论】: