MySQLdb and strings with quotes / long strings
chrisk at nipltd.com
Fri Jan 24 20:09:02 CET 2003
I'm trying to put email messages into a MySQL database. I'm happy enough
with the 65k character Text field length limit, however I'm having
trouble getting the data in.
I construct a SQL string insert into... set body='%s'... %(body)
body has had body = string.replace(body, "'", "''") done to it, which
should escape the strings with quotes in, but I get this traceback
Traceback (most recent call last):
File "mailboxreader.py", line 85, in ?
email.Utils.parsedate(message.get("Date")), message.get("SUBJECT"), body)
File "sql.py", line 74, in add_message
File "/usr/lib/python2.1/site-packages/MySQLdb/cursors.py", line 61,
r = self._query(query)
File "/usr/lib/python2.1/site-packages/MySQLdb/cursors.py", line 168,
rowcount = self._BaseCursor__do_query(q)
File "/usr/lib/python2.1/site-packages/MySQLdb/cursors.py", line 112,
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your
SQL syntax near 't actually do it''\n print ''\\t-p\\tmanager
permissions, in the form''\n prin' at line 1")
looks like the escaping did not work? How have other people got round
All ideas/advice appreciated.
More information about the Python-list