RE: [CDBI] before and after update values in before_update trigger

"Daniel Williams" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <5B0731A8753509478386ED3D6513B2D153CB71@isp-per-exch01.win2k.iinet.net.au>
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-Ra3b/[email protected]
[mailto:classdbi-bounces-Ra3b/[email protected]] On Behalf Of Sorin
Milutinovici
Sent: Monday, 1 May 2006 6:39 PM
To: classdbi-Ra3b/[email protected]
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-Ra3b/[email protected]
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.