Email::Store::Attachment - my losing battle
Matt Lawrence
matt.lawrence at virgin.net
Thu Nov 30 11:00:58 GMT 2006
Matt Lawrence wrote:
> Jonathan Stowe wrote:
>> On Wed, 2006-11-29 at 16:38 +0000, Chisel Wright wrote:
>>
>>> I knew MattL couldn't resist. I've got a bytea column for the payload
>>> now, and a hacked Email::Store::Attachment that now has:
>>>
>>> my $payload = $_->bodyhandle->as_string;
>>> $payload =~ s/([\x00-\x1f'\\\x7f-\xff])/'\\\\' . sprintf("%03o",
>>> ord($1))/eg;
>>>
>>> which does get successfully inserted.
>>>
>>
>> Yeah. If you read the Postgres documentation about the bytea data type
>> you will see that it does indeed say that certain non-printable
>> characters need to be escaped like that. The same applies to other
>> database systems.
>>
>>
> Since writing that I've spotted this in the DBD::Pg docs:
>
> $rv = $sth->bind_param($param_num, $bind_value,
> { pg_type => DBD::Pg::PG_BYTEA });
>
>
> Which is a much cleaner way to do this. So I guess the next problem is
> to get Class::DBI (or superclass) to handle that.
>
> I can't see anything obvious in the Class::DBI docs to declare column
> types.
>
There seems to be an undocumented feature in Class::DBI to allow this.
use DBD::Pg qw( :pg_types );
Email::Store::Attachment->datatype(payload => {pg_type => PG_BYTEA});
Might do the trick.
Matt
More information about the london.pm
mailing list