I am trying to populate a column with an XML string in MYSQL. When I run my python script I am getting the below error. I am using the filename as the id, I believe I am parsing the XML incorrectly somehow.
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 '
cursor = cnx.cursor(buffered=True)
tree = ET
for a in os.listdir(mydir):
if a.endswith(".xml"):
print os.path.basename(a)
j=ET.parse(mydir+"/"+a)
a = ''.join(a.split())
a = a[:-9]
root = j.getroot()
xmlstr = ET.tostring(root, encoding='utf8')
xmlstr
print a
query = """UPDATE %s.%s SET col1= (%s) WHERE col2 = (%s)""" % (mysql_db,mysql_table,xmlstr,a)
cursor.execute(query)
Do you know what is getting an error?
When I print query out prior to executing I get the below
UPDATE triageprediction.triagepredictionsamples SET CtXml= (<?xml version='1.0' encoding='utf8'?>
<CAS version="2">
<uima.cas.Sofa _id="3" _indexed="0" mimeType="text" sofaID="_InitialView" sofaNum="1" sofaString="The Enmore Practice
more xml.....
</uima.cas.FSArray>
</CAS>) WHERE REFERRALID = (1187116)
Traceback (most recent call last):
File "C:\XML_Formatter_v2\loadxml.py", line 47, in <module>
cursor.execute(query)
File "C:\Python27\lib\site-packages\mysql\connector\cursor.py", line 551, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Python27\lib\site-packages\mysql\connector\connection.py", line 490, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Python27\lib\site-packages\mysql\connector\connection.py", line 395, in _handle_result
raise errors.get_exception(packet)
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 '2">
<uima.cas.Sofa _id="3" _indexed="0" mimeType="text" sofaID="_InitialView' at line 1
querybefore executing. What do you see printed?