In <[EMAIL PROTECTED]>, Mike wrote:

> The example below shows that result of a marshaled data structure is
> nothing but a string
> 
>>>> data = {2:'two', 3:'three'}
>>>> import marshal
>>>> bytes = marshal.dumps(data)
>>>> type(bytes)
> <type 'str'>
>>>> bytes
> '{i\x02\x00\x00\x00t\x03\x00\x00\x00twoi\x03\x00\x00\x00t\x05\x00\x00\x00three0'
> 
> Now, I need to store this data safely in my database as CLEAR TEXT, not
> BLOB. It seems to me that it should work just fine since it is string
> anyways. So, why does O'reilly's Python Cookbook is insisting in saving
> it as a binary file and BLOB type?
> 
> Am I missing out something?

Yes, that a string is *binary* data.  But only a subset of strings is safe
to use as `TEXT` in databases.  Do you see all those '\x??' escapes? 
'\x00' is *one* byte!  A byte with the value zero.  Something your DB
doesn't allow in a `TEXT` type.

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to