Search code examples
pythonmysqlpymysql

Pymysql 1064, "You have an error in your SQL syntax


Could you please help check where is wrong with my SQL command? Thank you so much in advance.

The error is below.

pymysql.err.ProgrammingError: (1064, "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 '15:57:41, Addressing API Vulnerabilities in Connected Car Services and Fleets, A' at line 1")

My SQL is below.

title=escape_string(filtered_content[0][1])
author=escape_string(filtered_content[0][2])
publishdate=escape_string(filtered_content[0][3])
content=escape_string(filtered_content[0][4])
tags=escape_string(filtered_content[0][5])
url=escape_string(filtered_content[0][6])
dt=escape_string(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
sql = "INSERT INTO {} VALUES (NULL, {}, {}, {}, {}, {}, {}, {}) FROM DUAL WHERE NOT EXISTS(SELECT * FROM {} WHERE url={}".format(self.tableName, dt, title, author, publishdate, content, tags, url, self.tableName, url)
cursor.execute(sql)
db.commit()

Solution

  • There is no ) at the end of EXISTS(SELECT * FROM {} WHERE url={}