1

I'm trying to develop this SQL scoring system executed in python but I get the following error in Sublime, does anyone know how to resolve and adjust any potential future errors. I've looked at similar problems addressed on different stack questions, but can't find what I'm looking for?

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")
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Lamtheram
  • 89
  • 1
  • 7
  • 1
    All the values placeholders should be `%s`. This isn't string interpolation so `%d` and `%f` are not applicable. – snakecharmerb Nov 19 '20 at 19:15
  • Your title says MySQL, but you have tagged SQL Server and PySQLite? Both different RDBMS? Can you tidy up your tags please. – Dale K Nov 19 '20 at 19:15

1 Answers1

1

Duplicate of Not all parameters were used in the SQL statement (Python, MySQL)

Line # 14: Change to

sql = "INSERT INTO trial2 (Name, Age, BPsystolic, BPdiastolic, ClinicalFeaturesOfTheTia, DurationOfSymptoms, HistoryOfDiabetes, ABCD²ScoreForTIA) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
Dale K
  • 25,246
  • 15
  • 42
  • 71
  • Can you take a look here? https://stackoverflow.com/questions/72684970/execution-failed-on-sql-select-name-from-sqlite-master-where-type-table-and-n – Jnl Jun 20 '22 at 11:24