I was doing a python exam to retrieve data from table Employee using the following code:
name = input("Enter an employee's name: ")
cur.execute("SELECT * FROM Employee WHERE EmployeeName = (?)", (name,))
The output was correct as expected.
After submission ChatGPT said that adding parentheses around placeholders ?
might lead to syntax errors or incorrect query execution and the correct syntax should be:
cur.execute("SELECT * FROM Employee WHERE EmployeeName = ?", (name,))
I also read the sqlite3 documentation and they always demonstrate the ?
placeholder without parentheses when working with WHERE
clause. However there’s no clear explanation whether using (?)
was wrong or not.
Does using (?)
in my situation cause any malfunction? I’m worried that the exam might be wasted.
BigDip is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.