MySQLdb and strings with quotes / long strings

Chris Keyes chrisk at nipltd.com
Fri Jan 24 16:35:27 EST 2003


Hmm, thats clever

/me smacks head against screen, cheers I'll take a look. I noticed 
something about that in the documentation, but it didn't quite read like 
that :-)

Thanks Skip ;-)

Chris

Skip Montanaro wrote:
>     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