Insert blob data to MySQL

Alex Martelli aleax at aleax.it
Sat May 4 07:19:43 EDT 2002


Gerhard Häring wrote:
        ...
>>>>>> cc.execute("""INSERT INTO blobtbl (b) VALUES(%s)""", (s,))
>>> 1L
>> 
>> If s is 'anything' (e.g., a cPickle.dumps with binary option set),
>> MySQLdb.escape_string(s) is likely to work better than plain s
>> as the value to put in the tuple that's execute's second arg.
> 
> AFAIC you shouldn't need to do this. converters.Thing2Literal is the

Interesting!  I was convinced the escape_string was needed, but
testing right now (with the latest versions) confirms Gerhard's
suggestion -- I'm not sure where my misconception had come from
(or why it had apparently never 'bit' me -- sheer "luck" I guess!).

To give good info in exchange for good info:

> blob = "".join(map(lambda x: chr(x), range(256)))

Peculiarly redundant -- ''.join(map(chr, range(256))) being quite
equivalent.  And a good example of why we'd be better off without
lambda:-).


Alex




More information about the Python-list mailing list