python - Errors in SQL Syntax -
I am trying to run mysql query through a python script and by placing an error in my SQL syntax, I can see that the query has been set correctly. Can anyone give me a second set of eyes on this? Conn = mysql.connector.connect (** config) connect = conn.cursor () query = u'INSERT page_load_times (self, Values ({}, {}, {}, {}, {}) '. Format (self, self.object_id, self.page_header, t.interval, timestamp) Connect.execute (query) conn.commit () conn.close ()
I get the error It is below:
Programming error: 1064 (42000): There is an error in your SQL syntax; To use '13: 56: 17.491000 on line 1, check the manual related to your MySQL server version for the correct syntax.
Do not give query parameters through string formatting.
The mysql client works by passing the parameters in the second argument by execute () . With no quotes and data type conversion problems, you must avoid SQL injection risk: query = "" page_load_times (auto, object_id, page_header, ELAPSED_TIME, date_run) in value Enter (% (self) s,% (object_id) s,% (page_header) s,% (interval) s,% (timestamp)) "" "parameter = {'self': self, 'object_id': self. Object_id, 'page_header': self.page_header, 'interval': t.interval, 'timestamp': timestamp} connect.execute (query, parameter)
Comments
Post a Comment