Link to home
Start Free TrialLog in
Avatar of adbyits
adbyits

asked on

mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement

Good Afternoon all for some reason i am getting a error mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement, i have checked all the %s and they all show as 7 as well as all the items in the sql, i am sure is not much but if someone could take a look that would be great

    from requests_html import HTMLSession
import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  passwd="*****",
  database="flightdata"
)

mycursor = mydb.cursor()

# create an HTML Session object
session = HTMLSession()

# Use the object above to connect to needed webpage
resp = session.get("https://www.adelaideairport.com.au/flight-information/flight-search/?flt_no=&carrier=All&city=&dte=Current&leg=Departures")

# Run JavaScript code on webpage
resp.html.render()


airline_spans = resp.html.find('.SearchResultFlightListRow')
print (airline_spans)
airline_list = [span.text.split('\n') for span in airline_spans]

for flight in airline_list:
    if len(flight) == 7:
        flightno, From, to, scheduled, estimated, gate, status = flight
        print ("This is a " + estimated)
        if estimated == "":
            print (" currently no dely ")
            print ("This is a " + estimated)
            estimated = 'IDEL'
        print (f'Flight no {flightno} from  {From} to {to} is scheduled to depart at {scheduled} from gate {gate} and flight status is {status}')

    elif len(flight) == 6:
        flightno, From, to, scheduled, estimated, gate = flight
        status = 'IDEL'
        print ("This is a " + estimated)
        if estimated == "":
            print (" currently no dely ")
            print ("This is a " + estimated)
            estimated = 'IDEL'
        print (f'Flight no {flightno} from  {From} to {to} is scheduled to depart at {scheduled} from gate {gate} ')

    elif len(flight) == 5:
        flightno, From, to, scheduled, estimated = flight
        gate = 'IDEL'
        status = 'IDEL'
        print ("This is a " + estimated)
        if estimated == "":
            print (" currently no dely ")
            print ("This is a " + estimated)
            estimated = 'IDEL'

print (f'Flight no {flightno} from  {From} to {to} is scheduled to depart at {scheduled} from gate ')


sql = "INSERT INTO flightinfo (origin, airline, destinations, flightNumbers, scheduledTime, estimatedTime, status) VALUES (%s, %s, %s, %s, %s, %s, %s)"

val = (From, to, flightno, scheduled, estimated, status, gate)
#data.append(val)


# doing a batch insert
mycursor.executemany(sql, val)

mydb.commit()

print(mycursor.rowcount, "was inserted.")
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

sql = "INSERT INTO flightinfo (origin, airline, destinations, flightNumbers, scheduledTime, estimatedTime, status) VALUES (%s, %s, %s, %s, %s, %s, %s)"

This means to me that if %s = "yabbadabadoo"
then origin = "yabbadabadoo"
...
status = "yabbadabadoo"

I do not see in your code where %s is defined.
Avatar of adbyits
adbyits

ASKER

I might have missed it mate  i am still raw as on this csn you pmease tell me were i need to add it
print (f'Flight no {flightno} from  {From} to {to} is scheduled to depart at {scheduled} from gate {gate} and flight status is {status}')
sql = "INSERT INTO flightinfo (origin, airline, destinations, flightNumbers, scheduledTime, estimatedTime, status) VALUES (from, %s,to, flightno, scheduled, %s, status)"

you need to replace the  %s with the values I'm missing one or have an extra one somewhere
Avatar of adbyits

ASKER

Thanks David just a question here is code i have working that i use json with and i have the same insert string and it works, just wondering why



import urllib.parse
import requests
import mysql.connector
import pandas as pd


mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  passwd="*****",
  database="flightdata"
)

mycursor = mydb.cursor()




url = 'https://www.bne.com.au/sites/default/files/00API-Today.json?nocache=true'


#address = 'true'
#url = main_api + urllib.parse.urlencode({address: address})

response_data = requests.get(url).json()
# empty list for holding all the data
data = []
for element in response_data:
    origin = element['DepartureAirportName']
    flight_id = element['Id']
    airline = element['AirlineName']
    destination = element['ToFrom']
    flightNumbers = element['FlightNumber']
    scheduledTime = element['ScheduledTimeTime']
    estimatedTime = element['EstimatedTimeTime']
    scheduledDate = element['ScheduledTimeEuro']
    latestTime = element['EstimatedTimeTime']
    status = element['Status']
    print (origin, flight_id, flightNumbers, airline, destination, scheduledTime, scheduledDate, latestTime, status)

    sql = "INSERT INTO flightinfo (origin, id, airline, destinations, flightNumbers, scheduledTime, estimatedTime, scheduledDate, latestTime, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"

    val = (origin, flight_id, airline, " ".join(destination), ", ".join(flightNumbers), scheduledTime, estimatedTime,
            scheduledDate, latestTime, status)
    data.append(val)


# doing a batch insert
mycursor.executemany(sql, data)

mydb.commit()

print(mycursor.rowcount, "was inserted.")


#print(val)
#print(pd.datetime.now().date())
Hello, in the first case the values in val do not match the fields  order in  sql insert into
Below, I try to "visually" illustrate the problem:

User generated image
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.