MySQLdb and strings with quotes / long strings
Skip Montanaro
skip at pobox.com
Fri Jan 24 14:22:45 EST 2003
Chris> I'm trying to put email messages into a MySQL database. I'm happy
Chris> enough with the 65k character Text field length limit, however
Chris> I'm having trouble getting the data in.
Chris> I construct a SQL string insert into... set body='%s'... %(body)
Chris> body has had body = string.replace(body, "'", "''") done to it,
Chris> which should escape the strings with quotes in, but I get this
Chris> traceback
It's probably easier to just let MySQL do the quoting:
con = MySQLdb.Connection(...)
cur = con.cursor()
cur.execute("insert into ... set body=%s ...", (body,))
Skip
More information about the Python-list
mailing list