[Zope] blob image from MySql

Andy Dustman farcepest at gmail.com
Mon Feb 28 23:04:44 EST 2005


On Tue, 1 Mar 2005 02:42:26 +0100, Adriano <adriano at euma.com> wrote:
> Phillip,
> 
> Thanks for your kindness, you got a point.
> 
> I checked and the first row of the file "downloaded" starts with
> "array('c', ... and then all the strange chars
> 
> Also, I tried to put an external method like this:
> 
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> def makeImage(self, photo):
>      return photo[0].iconblob.tostring()
> 
> (notice the ".tostring()" in the end)

I think I now know the answer.

ZMySQLDA uses the converter dictionary from MySQLdb, though it mostly
bypasses MySQLdb. Since 1.0.0, MySQLdb returns BLOB columns as
array(c,...), and previously it returned strings, so now it runs afoul
of Zope, which expects a string.

There is a section ZMySQLDA/db.py in the DB class that looks like this:

    conv=conversions.copy()
    conv[FIELD_TYPE.LONG] = int_or_long
    conv[FIELD_TYPE.DATETIME] = DateTime_or_None
    conv[FIELD_TYPE.DATE] = DateTime_or_None
    conv[FIELD_TYPE.DECIMAL] = float
    del conv[FIELD_TYPE.TIME]

You should add a line after this:

    del conv[FIELD_TYPE.BLOB]

This will cause it to return BLOBs as strings.

I'll have to fix this in ZMySQLDA.
-- 
Computer interfaces should never be made of meat.

Using GMail? Setting Reply-to address to <> disables this annoying feature.

You are in a maze of twisty little passages all alike.
To go north, press 2. To go west, press 4.
To go east, press 6. To go south, press 8. 
If you need assistance, press 0 and a little dwarf
will assist you.


More information about the Zope mailing list