I have a Flask app that is executing an sql query to retrieve a list of parts from a MySql database. My problem is that I am sure I have the SQL query correct, because it works in MySql workbench, but when I run the same query in the app is returns an empty list.
I am fairly new to this so go easy on me.
SQL query:
SELECT job_part.*, part.part_name, part.cost
FROM job_part
JOIN part ON job_part.part_id = part.part_id
WHERE job_part.job_id = 5;
my Python
connection = getCursor()
sql = """SELECT job_part.*, part.part_name, part.cost
FROM job_part
JOIN part ON job_part.part_id = part.part_id
WHERE job_part.job_id = %s;"""
connection.execute(sql, (jobNo,))
partList = connection.fetchall()
connection.close()
print(partList)
jobNo is 5 as a str, I have tried converting to int but no difference
I get [] in the terminal
2
Answers
Thanks to all who offered help. I had been using mysql 8.2 and been getting a version mismatch error in workbench whenever I started it, and had been ignoring it, hadn't caused any obvious problems. In the end uninstalling mysql and workbench and installing v8.0 for both resolved this issue. Lesson leanred.
Try to narrow down the cause of the problem. Could be:
I’m leaning for (2). Try to follow these troubleshooting steps: change the query and use a static job_id. If that works, then you know it’s got to do with variable substitution.