[Ape] MySQL character arrays
Roché Compaan
roche at upfrontsystems.co.za
Sat Nov 27 05:41:37 EST 2004
MySQLdb returns blob columns as character arrays which makes it
impossible for Ape to deserialize pickles.
Traceback:
2004-11-27T09:40:47 ERROR(200) ZODB Couldn't load state for '6'
Traceback (most recent call last):
File "/home/roche/zope-instances/simpill/Products/Ape/lib/apelib/zodb3/connection.py", line 359, in setstate
event = osio.deserialize(oid, obj, classification, state)
File "/home/roche/zope-instances/simpill/Products/Ape/lib/apelib/core/io.py", line 160, in deserialize
mapper.serializer.deserialize(event, state)
File "/home/roche/zope-instances/simpill/Products/Ape/lib/apelib/core/serializers.py", line 121, in deserialize
s.deserialize(event, state)
File "/home/roche/zope-instances/simpill/Products/Ape/lib/apelib/zodb3/serializers.py", line 296, in deserialize
s = u.load()
UnpicklingError: unpickling stack underflow
The value of 'data' in deserialize:
2004-11-27T09:40:47 INFO(0) INFO
apelib.zodb3.serializers.remainingstate.deserialize> data: 'array(\'c\', "# pickle-base-64 contents:\\n# \'contributors\'\\n# \'creation_date\'\\n# \'description\'\\n# \'effective_date\'\\n# \'expiration_date\'\\n# \'format\'\\n# \'language\'\\n# \'modification_date\'\\n# \'rights\'\\n# \'subject\'\\nXXEBKChVDGNvbnRyaWJ1dG9yc3ECKXRxAyhVDWNyZWF0aW9uX2RhdGVxBChjRGF0ZVRpbWUuRGF0\\nZVRpbWUKRGF0ZVRpbWUKcQVOb3EGfXEHKFUIX25lYXJzZWNxCEdAQYAAAAAAAFUHX3NlY29uZHEJ\\nR0BBtHrhR64UVQNfdHpxClUFR01UKzJxC1UHX3BtaG91cnEMSwlVCl9kYXlvZmZzZXRxDUsGVQVf\\nZmRheXEOVQhTYXR1cmRheXEPVQVfYW1vbnEQVQNOb3ZxEVUCX3RxEkdB0GoKodo9cVUDX3BtcRNV\\nAmFtcRRVBHRpbWVxFUc/04mPKawAAFUHX21pbnV0ZXEWSxNVBl9tb250aHEXSwtVBV9hZGF5cRhV\\nA1NhdHEZVQVfaG91cnEaSwlVB19taWxsaXNxG0wxMTAxNTM5OTc1NDEwTApVBF9kYXlxHEsbVQVf\\neWVhcnEdTdQHVQVfcG1vbnEeVQROb3YucR9VBV9wZGF5cSBVBFNhdC5xIVUFX2Ztb25xIlUITm92\\nZW1iZXJxI1UCX2RxJEdA4ofpxMeU1nVidHElKFULZGVzY3JpcHRpb25xJlUAdHEnKFUOZWZmZWN0\\naXZlX2RhdGVxKE50cSkoVQ9leHBpcmF0aW9uX2RhdGVxKk50cSsoVQZmb3JtYXRxLFUJdGV4dC9o\\ndG1scS10cS4oVQhsYW5ndWFnZXEvVQB0cTAoVRFtb2RpZmljYXRpb25fZGF0ZXExaAZ0cTIoVQZy\\naWdodHNxM1UAdHE0KFUHc3ViamVjdHE1KXRxNmUuXXE3Lg==\\n")'
Attached is a patch to fix this.
--
Roché Compaan
Upfront Systems http://www.upfrontsystems.co.za
-------------- next part --------------
--- lib/apelib/sql/mysql.py 2004-07-21 08:38:05.000000000 +0200
+++ lib/apelib/sql/mysql.py 2004-11-27 11:27:05.000000000 +0200
@@ -16,10 +16,24 @@
$Id: mysql.py,v 1.2 2004/07/21 06:38:05 shane Exp $
"""
-from apelib.sql.dbapi import AbstractSQLConnection
+from apelib.sql.dbapi import AbstractSQLConnection, RDBMSColumn
+
+class MySQLBlobColumn(RDBMSColumn):
+ """Translates MySQL driver's character array to string"""
+
+ use_conversion = True
+
+ def from_db(self, value):
+ return value.tostring()
+
class MySQLConnection (AbstractSQLConnection):
+ column_factories_by_name = {
+ 'pickle': MySQLBlobColumn,
+ 'data': MySQLBlobColumn,
+ }
+
column_type_translations = {
'long': 'bigint',
'string': 'character varying(255)',
More information about the Ape
mailing list