You need to enable JavaScript to run this app. Python向SQLite3插入字典时出现参数绑定错误的问题求助
优惠活动
大模型
产品
解决方案
定价
更多

Python向SQLite3插入字典时出现参数绑定错误的问题求助

问题原因

你的错误是cursor.execute()方法的括号闭合位置错误,导致用于参数绑定的字典没有被传入方法内。

你写的代码里,将execute的右括号放在了SQL语句的末尾:

# 错误写法
self.cursor.execute('INSERT INTO ......;'), var_dict

这种写法相当于execute方法仅接收了SQL语句一个入参,后面的var_dict和execute的返回值组成了无意义的元组,没有实际作用。SQLite无法识别到你准备的14个绑定参数,因此抛出了对应报错。

修复方案

将execute的右括号移动到var_dict后面即可,修正后的代码如下:

def insertRecords(self):
    self.cursor.execute('INSERT INTO records (Budget,Commitment,Contract_Type,Customer_Type,Duration,Goals,Pace,'
                                             'Procedures_and_Regulations,Resources,Scope,Team_Availability,'
                                             'Team_Distribution,Team_Size,Uncertainty) '
                        'VALUES (:Budget, :Commitment, :Contract_Type, :Customer_Type, :Duration, '
                                ':Goals, :Pace, :Procedures_and_Regulations, :Resources, :Scope, :Team_Availability, '
                                ':Team_Distribution, :Team_Size, :Uncertainty);', var_dict)
    self.connection.commit()

内容的提问来源于stack exchange,提问作者User1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.19 04:45:06