MySQL Forums :: Python :: Python/Connect and Placeholders
Python/Connect and Placeholders
Date: March 01, 2013 02:45AM
Maybe this is too late in the evening, but this is driving me nuts. I have an SQL statement with one placeholder:
sql = ("SELECT * FROM source AS s INNER JOIN bar AS B ON B.id = bar WHERE s.name = %s")
cursor = conn.cursor()
cursor.execute(sql, (source))
I always get an SQL error: mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1
However, when I modify the where clause to take the same variable twice, it works as intended.
sql = ("SELECT * FROM source AS s INNER JOIN bar AS B ON B.id = bar WHERE s.name = %s OR s.name = %s")
cursor = conn.cursor()
cursor.execute(sql, (source, source))
Anyone with an idea of what's going on?
Edited 2 time(s). Last edit at 03/01/2013 02:46AM by Shu Chow.
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.