[CDBI] Sybase Image Column Inflate/Deflate
dhoworth at mrc-lmb.cam.ac.uk
Tue Jun 28 10:51:13 BST 2011
eric.berg at barclayscapital.com wrote:
> Many years ago someone made the decision to put XML which defines
> reports into one of our tables in a Sybase DB into an image field.
> The XML stored in this column is encoded as hex. I'm working on a
> cdbi class that will access that table, and am not sure how to
> proceed in order to implement the pack/unpack required to convert the
> data in these binary image columns between hex and a doceoded string.
> Initially, I thought it would be to use the inflate/deflate
> attributes of the has_a() method, but that doesn't seem to be the
> case, because it looks like the has_a() is expecting to inflate to an
> object, but this is just text.
I think your understanding is correct but it may not be a problem that
the column becomes an object because presumably you'll be using the text
as the content of some kind of XML object. In which case just add the
inflate method to the target class (subclass or horror, inject).
> It appears as if I can use a select_trigger and then set the
> attribute using the _attribute_store() method so that it doesn't get
> propagated back to the DB, and then use the before_set() method to
> change the value back to hex before my class pesrists the value of
> the field.
Wouldn't you just write your column accessor as a wrapper around
_attrs() and the mutator as a wrapper around _attribute_set() ? Of
course you could combine them in a single accessor-mutator method.
So either technique will work, I think; which to choose depends on your
More information about the ClassDBI