October 26, 2024
Chicago 12, Melborne City, USA
python

“Not all parameters were used in the SQL statement” (Python,MySQL) error confusion


I get an error when trying to insert into the database table with the following code

import mysql.connector
import re

mydb = mysql.connector.connect(
  host="",
  user="",
  password="",
  database ="db"
)
mycursor = mydb.cursor()

sql = "INSERT INTO characters (url, name, disambiguation) VALUES (%s, %s, %s)"
val = []
with open("text.txt","r",encoding="utf-8") as f:
    for line in f.readlines():
      x = re.findall(r'"(.*?)"', line)
      x= x[::-1]
      x.append("")
      val.append(x)

mycursor.executemany("INSERT INTO characters (name, url, disambiguation) VALUES (%s, %s, %s)", val)
mydb.commit()

The contents of val looks like this:

[["'Lectron (Earth-12772)", '/wiki/%27Lectron_(Earth-12772)', ''], ["'Selka (Earth-928)", '/wiki/%27Selka_(Earth-928)', ''], ["'Spinner (Earth-616)", '/wiki/%27Spinner_(Earth-616)', ''],...]

While the query DESCRIBE TABLE returns this:

('name', 'varchar(255)', 'YES', '', None, '')
('url', 'varchar(255)', 'YES', '', None, '')
('disambiguation', 'varchar(255)', 'YES', '', None, '')

If there’s only three parameters and i’m passing all three in i don’t know why i’m receiving the error



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video