[CDBI] before and after update values in before_update trigger

Daniel Williams danielw at staff.iinet.net.au
Mon May 1 12:02:43 BST 2006


Not sure if this is the best way to do it but heres how I do it:

Blah->columns(Primary => qw/oid/);
Blah->columns(Essential => qw/column1 column2 column3 column4/);

# these are the columns that we want to store log info for
my @log_cols = qw/column1 column2 column3 column4/;

Blah->add_trigger( map { 'before_set_'. $_ => \&col_saver } @log_cols )
;
Blah->add_trigger( before_update => \&before_update ) ;

sub col_saver {
    my $self = shift ;
    return unless (ref($self)) ;
    my ($new, $argsR) = @_ ;

    foreach my $key (keys %$argsR) {
        $self->{cdbi_oldvals}->{$key} = $self->get($key) ;
    }
}

sub before_update {
	my $self = shift;
	# Old Value
	$self->{cdbi_oldvals}->{column}
	# New Value
	$self->column;
}


Daniel

-----Original Message-----
From: classdbi-bounces at lists.digitalcraftsmen.net
[mailto:classdbi-bounces at lists.digitalcraftsmen.net] On Behalf Of Sorin
Milutinovici
Sent: Monday, 1 May 2006 6:39 PM
To: classdbi at lists.digitalcraftsmen.net
Subject: [CDBI] before and after update values in before_update trigger

Hi everyone,

I'm not using Class::DBI for long so this may be a simple question:

Is it possible to obtain in a before_update trigger both values of an
updated 
field - the value before the fileld was updated and the value that will
be 
assigned to that field after update?

If the answer is yes, how can I do that? 

Now, $self->{field} gives me the value _after_ update, even in
before_update 
trigger.

If the answer is no - can (and should) be implemented somehow?

Thank you,

Sorin Milutinovici

-- 
Semper in excrementul sole profundum qui variat

_______________________________________________
ClassDBI mailing list
ClassDBI at lists.digitalcraftsmen.net
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi






More information about the ClassDBI mailing list