Re: [CDBI] Sybase Image Column Inflate/Deflate

Dave Howorth <dhoworth-fDajt2Yx3S8pY9vWkoisglpr/1R2p/[email protected]> Tue, 28 Jun 2011 10:51:13 +0100
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Organization MRC Centre for Protein Engineering
Message-ID <[email protected]>
[email protected] 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
API requirements.

TMTOWTDI, Dave