MySQLdb + Python + quotes

Fredrik Lundh effbot at telia.com
Tue May 9 18:33:52 EDT 2000


Lars Hoeyrup Jensen <robinhat at rhk.dk> wrote:
> I use the MySQLdb module to make Python interact with MySQL. I have a
> problem, when I try to insert strings that contain special characters
> (here I primarily think of quotes: ' and "). There _must_ be a smart
> way to escape these characters.

from the recent "BLOBS and python" thread:

    ...

    From: Oleg Broytmann <phd at phd.russ.ru>
    Date: Fri, 5 May 2000 08:26:36 +0000 (GMT)
    Subject: Re: BLOBS and python

    On Thu, 4 May 2000, sp00fD wrote:
    > con.execute("INSERT INTO foo (myblob) VALUES ('%s')" % image)

    con.execute("INSERT INTO foo (myblob) VALUES ('%s')" % MySQL.escape(image))
                                                           ^^^^^^^^^^^^ !!!

    ...

hope this helps!

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->






More information about the Python-list mailing list