Re: [Zope] blob image from MySql
On Tue, 1 Mar 2005 02:42:26 +0100, Adriano <adriano@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.
Andy, thanks so much for your help, I would have never looked for the db.py module in ZMySQLDA. Really ! Still...
On Tue, 1 Mar 2005 02:42:26 +0100, Adriano <adriano@euma.com> wrote:
Phillip,
...
"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.
I found the db.py file and updated it adding the del conv[FIELD_TYPE.BLOB] row, as you suggested. I restarted Zope in order to let it load the modified product but the problem is still there. Well, there's no longer the "array(c,...) starting; But it still doesn't work correctly To be more specific, the downloaded file now starts like: ???JFIFHH??C it looks not that bad, does it ? ;) Well, I don't know. Thank you, anyhow Bye Catonano -- " One of the tricks here is to get away from thinking that programs have to be composed with only a simple text editor " - Alan Kay - "Java and C++ make you think that the new ideas are like the old ones. Java is the most distressing thing to hit computing since MS-DOS". - Alan Kay - "The computer revolution hasn't started yet. Don't be misled by the enormous flow of money into bad defacto standards for unsophisticated buyers using poor adaptations of incomplete ideas". -Alan Kay -
participants (2)
-
Adriano -
Andy Dustman