Per column filter

6 messages Options
Embed this post
Permalink
Pedro Melo

Per column filter

Reply Threaded More More options
Print post
Permalink
Hi,

I'm wrapping DBIx::Class over a legacy database that uses the  
iso-8859-1 charset internally. My app expects all perl strings as utf8.

I'm trying to write an extension to DBIC that decodes the value from  
the DB into utf8, and does the reverse when I insert/update data. At  
first I tried to use the InflateColumn as the base of this, but it  
expects a DB -> Object / Object -> DB flow, and cannot support the DB -
 > scalar / scalar -> DB (at least not on the deflate part).

I was wondering if anybody has any ideas/suggestions on how to do this  
inside DBIC. I would prefer not to manually encode/decode data I get  
from the DB.

Basically a setup like the current InflateColumn but that allows  
scalars to be processed on the deflate step would work, like a filter.

Thanks in advance,
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: [hidden email]
Use XMPP!



_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Moritz Onken

Re: Per column filter

Reply Threaded More More options
Print post
Permalink

Am 18.06.2009 um 14:18 schrieb Pedro Melo:

> Hi,
>
> I'm wrapping DBIx::Class over a legacy database that uses the  
> iso-8859-1 charset internally. My app expects all perl strings as  
> utf8.
>
> I'm trying to write an extension to DBIC that decodes the value from  
> the DB into utf8, and does the reverse when I insert/update data. At  
> first I tried to use the InflateColumn as the base of this, but it  
> expects a DB -> Object / Object -> DB flow, and cannot support the  
> DB -> scalar / scalar -> DB (at least not on the deflate part).
>
> I was wondering if anybody has any ideas/suggestions on how to do  
> this inside DBIC. I would prefer not to manually encode/decode data  
> I get from the DB.
>
> Basically a setup like the current InflateColumn but that allows  
> scalars to be processed on the deflate step would work, like a filter.

Have a look at store_column which you can override in a result class.
 From the docs:

"This is the lowest level at which data is set on a row object, extend  
this method to catch all data setting methods."

cheers,

moritz

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Daniel Ruoso

Re: Per column filter

Reply Threaded More More options
Print post
Permalink
In reply to this post by Pedro Melo
Em Qui, 2009-06-18 às 13:18 +0100, Pedro Melo escreveu:
> I'm wrapping DBIx::Class over a legacy database that uses the  
> iso-8859-1 charset internally. My app expects all perl strings as utf8.

I think you could consider changing the encoding of the DB connection,
before trying to do that as inflate/deflate. It's the responsability of
the driver to get the strings correct inside Perl.

daniel


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Pedro Melo

Re: Per column filter

Reply Threaded More More options
Print post
Permalink
Hi,

On Jun 18, 2009, at 7:52 PM, Daniel Ruoso wrote:

> Em Qui, 2009-06-18 às 13:18 +0100, Pedro Melo escreveu:
>> I'm wrapping DBIx::Class over a legacy database that uses the
>> iso-8859-1 charset internally. My app expects all perl strings as  
>> utf8.
>
> I think you could consider changing the encoding of the DB connection,
> before trying to do that as inflate/deflate. It's the responsability  
> of
> the driver to get the strings correct inside Perl.

Not sure if the driver will recode from iso-8859-1 into UTF8 but I'll  
try.

Thanks,
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: [hidden email]
Use XMPP!



_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Pedro Melo

Re: Per column filter

Reply Threaded More More options
Print post
Permalink
In reply to this post by Moritz Onken
Hi,

On Jun 18, 2009, at 1:27 PM, Moritz Onken wrote:

> Am 18.06.2009 um 14:18 schrieb Pedro Melo:
>> I'm wrapping DBIx::Class over a legacy database that uses the  
>> iso-8859-1 charset internally. My app expects all perl strings as  
>> utf8.
>>
>> I'm trying to write an extension to DBIC that decodes the value  
>> from the DB into utf8, and does the reverse when I insert/update  
>> data. At first I tried to use the InflateColumn as the base of  
>> this, but it expects a DB -> Object / Object -> DB flow, and cannot  
>> support the DB -> scalar / scalar -> DB (at least not on the  
>> deflate part).
>>
>> I was wondering if anybody has any ideas/suggestions on how to do  
>> this inside DBIC. I would prefer not to manually encode/decode data  
>> I get from the DB.
>>
>> Basically a setup like the current InflateColumn but that allows  
>> scalars to be processed on the deflate step would work, like a  
>> filter.
>
> Have a look at store_column which you can override in a result class.
> From the docs:
>
> "This is the lowest level at which data is set on a row object,  
> extend this method to catch all data setting methods."

Thanks, I'll try this.

Best regards,
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: [hidden email]
Use XMPP!



_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Daniel Ruoso

Re: Per column filter

Reply Threaded More More options
Print post
Permalink
In reply to this post by Pedro Melo
Em Sex, 2009-06-19 às 13:36 +0100, Pedro Melo escreveu:

> > Em Qui, 2009-06-18 às 13:18 +0100, Pedro Melo escreveu:
> >> I'm wrapping DBIx::Class over a legacy database that uses the
> >> iso-8859-1 charset internally. My app expects all perl strings as  
> >> utf8.
> > I think you could consider changing the encoding of the DB connection,
> > before trying to do that as inflate/deflate. It's the responsability  
> > of
> > the driver to get the strings correct inside Perl.
> Not sure if the driver will recode from iso-8859-1 into UTF8 but I'll  
> try.

Which database? Every database I know does that...

daniel


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...