[Dbix-class] inflate_column help

xyon xyon at indigorobot.com
Wed Mar 26 21:00:58 GMT 2008


Hello everyone,

I am trying to wrap my head around using "inflate_column" to
decrypt/encrypt AES Encrypted data from within a MySQL database, but
have not found any examples on Google. Also, below is an attempt to
figure out how to run raw SQL queries with DBIx::Class.

Here is some code and other info:

Versions:
------------------------------------------------------------------------
# rpm -q perl perl-DBIx-Class mod_perl httpd
perl-5.8.8-11
perl-DBIx-Class-0.08009-1
mod_perl-2.0.3-1.el4s1.3
httpd-2.0.59-1.el4s1.10.el4.centos
------------------------------------------------------------------------



Myserver/Main.pm:
------------------------------------------------------------------------
package Myserver::Main;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_classes(qw/session/);

1;
------------------------------------------------------------------------



Myserver/Main/session.pm:
------------------------------------------------------------------------
package Myserver::Main::session;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('session');
__PACKAGE__->add_columns(qw/ id enc /);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->inflate_column('enc', {
                                inflate => \&decrypt,
                                deflate => \&encrypt, });
sub decrypt {
    my $self    = shift;
    my @return  = $schema->storage->dbh_do(
        sub {
            my ($storage, $dbh, $column, $id)    = @_;
            $dbh->select("SELECT AES_DECRYPT($column, 'datakey') AS
$column FROM session WHERE id=$id");
        }
    );
return @return;
}
------------------------------------------------------------------------



-- 
xyon <xyon at indigorobot.com>




More information about the DBIx-Class mailing list