I am trying to update some data into a mysql table, there are no warnings/errors produced but the data inserted has an extra character 0 and the string is truncated. This is the code from Python shell:
>>> len(d) #d is a string with contents of an html email
12347
>>> d[:100]
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.=\r\nw3.org/TR/html4/loose.'
>>> a = mysql.connector.connect(user='root', password='mypass', database='mydb')
>>> cur = a.cursor(prepared=True)
>>> cur.execute('UPDATE emails set content=? where emailid=10', (d,))
>>> a.commit()
>>> cur.execute('SELECT content from emails WHERE emailid=10')
>>> cur.fetchall()
[('0<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional/',)]
As you can see the content is truncated and also has an extra '0' . The type of 'content' field is MEDIUMTEXT, I tried with and without sql_mode as strict, but the result is same.
prepared=True
, this is a known bug in mysql-connector-python bugs.mysql.com/bug.php?id=73690 which will be fixed in upcoming versions. – Peeyush Sep 26 '14 at 12:47