tags:

views:

184

answers:

1

How does one use binary data (BLOB type column) in SQLAlchemy.

I just created a table with fields key, val, where val is BLOB and when I query the table, SQLAlchemy returns:

<read-only buffer for 0x83c3040, size -1, offset 0 at 0x83c3120>

How do I use this read-only buffer?

Please help.

With sincerity, Boda Cydo.

+1  A: 

You can iterate over it (e.g. for streaming it) or convert it to a string/binary if you want to have the whole binary in memory (which shouldn't be a problem as long as you are not dealing with movies in the database...)

>>> from sqlalchemy.util import buffer
>>> var = buffer('foo')
>>> var
<read-only buffer for 0xb727fb00, size -1, offset 0 at 0xb727fa80>
>>> str(var)
'foo'
>>> for i in var:
...   print i
... 
f
o
o

Regards, Christoph

tux21b
Thanks, this worked, `str(var)` was what I needed. :)
bodacydo