python - 不是所有参数都用在SQL语句python、MySQL
问题描述
我正在尝试开发这个在 python 中执行的 SQL 评分系统,但在 Sublime 中出现以下错误,有谁知道如何解决和调整任何潜在的未来错误。我已经查看了针对不同堆栈问题解决的类似问题,但找不到我要查找的内容?
Traceback (most recent call last):
File "C:\Users\User\Desktop\python\demo.py", line 20, in <module>
mycursor.executemany(sql, val)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 668, in executemany
stmt = self._batch_insert(operation, seq_params)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 613, in _batch_insert
raise errors.ProgrammingError(
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
import mysql.connector
db = mysql.connector.connect(
host="localhost",
port="3306",
user="root",
passwd="root",
database="trial1"
)
mycursor = db.cursor()
mycursor.execute("CREATE TABLE trial2 (Name TEXT NULL , Age INT NULL , BPsystolic INT NULL , BPdiastolic INT NULL , ClinicalFeaturesOfTheTIA TEXT NULL , DurationOfSymptoms INT NULL , HistoryOfDiabetes TEXT NULL , ABCD²ScoreForTIA FLOAT NULL )")
sql = "INSERT INTO trial2 (Name, Age, BPsystolic, BPdiastolic, ClinicalFeaturesOfTheTia, DurationOfSymptoms, HistoryOfDiabetes, ABCD²ScoreForTIA) VALUES (%s, %d, %d, %d, %s, %d, %s, %f)"
val = [
('Person A', '71', '137', '85', 'Speech disturbance without weakness', '17', 'Yes', None),
('Person B', '92', '125', '78', 'Other symptoms', '43', 'Yes', None),
('Person C', '27', '130', '90', 'Other symptoms', '34', 'No', None)
]
mycursor.executemany(sql, val)
mydb.commit()
print(mycursor.rowcount, "was inserted.")
sql = "UPDATE trial2 SET ABCD²ScoreForTIA = ((Age >= 60) + (BPsystolic >= 140) + (BPdiastolic >= 90) + case ClinicalFeaturesOfTheTia when 'Unilateral weakness' then 2 when 'Speech disturbance without weakness' then 1 when 'Other symptoms' then 0 end + case when DurationOfSymptoms >= 60 then 2 when DurationOfSymptoms >= 10 then 1 when DurationOfSymptoms < 10 then 0 end + (HistoryOfDiabetes = 'Yes')) / 8 where ABCD²ScoreForTIA is null)"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, "record(s) affected")
解决方案
SQL 语句中未使用所有参数的重复项(Python、MySQL)
第 14 行:更改为
sql = "INSERT INTO trial2 (Name, Age, BPsystolic, BPdiastolic, ClinicalFeaturesOfTheTia, DurationOfSymptoms, HistoryOfDiabetes, ABCD²ScoreForTIA) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
推荐阅读
- python - Pyqtgraph在图中颜色特定区域
- python - 创建一个 CSV 文件,其中包含两个在 python 中包含 UTF-8 的列表
- html - 尽管该笔记本已连接到互联网,但 HTML 代码出现错误
- kubernetes-helm - 是否可以在安装 helm 图表时根据 helm 客户端动态更新 Chart.yaml 中的 apiVersion?
- java - 在Java正则表达式中剪切多行文本的一部分
- arrays - 当命令失败时使脚本继续
- php - 如何在 Laravel 中使用 get route 插入数据发布
- java - Java 8 Compiler Plugin:如何在构造函数中添加 super() 调用?
- tinymce - 在 TinyMCE 中停止 html 格式化
- javascript - 将对象值组合到单个对象中