I have two tables StepNo (which is step number ) and stepText ( as every step has step text )
Now I try to retrieve a text from a database table to a text label I have in my UI (I did insert them from another UI that insert the stepText And StepNo into the database but I cant retrieve them
l stands for the label
def step2():
result = search_step(2)
l["text"] =['stepNo']
and those are the codes in db_setup
def add_to_step(stepText, stepNo):
print(stepText)
print(stepNo)
sql = """INSERT INTO `steps`(`stepText`, `stepNo`) VALUES (%s,%s)"""
c.execute(sql, (stepText, stepNo))
result = c.fetchone()
conn.commit()
print("add to step: ", result)
return result
def search_step(stepNo):
print(stepNo)
sql = """SELECT * FROM `steps` WHERE stepNo = %s"""
c.execute(sql, stepNo)
result = c.fetchone()
conn.commit()
print("selected step: ", result)
return result
And this is the code of the label
# Create label
l = Label(window, text = "Change the paragraph font to Arial",)
l.config(font =("Calibri", 14))
l.pack(pady=40)
l.place(relx = 0.5,
rely = 0.5,
anchor = 'center')
and it gives me this error
File "c:\Users\maroc\OneDrive\Desktop\mouse features29-3\mouse features\stepsui.py", line 19, in step2
result = search_step(2,)
File "c:\Users\maroc\OneDrive\Desktop\mouse features29-3\mouse features\db_setup.py", line 49, in search_step
c.execute(sql, stepNo)
File "C:\Users\maroc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\cursor.py", line 562, in execute
raise errors.ProgrammingError(
mysql.connector.errors.ProgrammingError: Could not process parameters: int(2), it must be of type list, tuple or dict
I really need help for this situation as it is very important to me thanks in advance
execute works for an arbitrary number of parameters, which means it doesn't know or care that your particular SQL command only needs one. You still have to provide a sequence (typically a tuple).
sql = """SELECT * FROM `steps` WHERE stepNo = %s"""
c.execute(sql, (stepNo,))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With