Re: Calculation of non-database columns

[prev] [thread] [next] [Date index for 2005/06/02]

From: Cees Hek
Subject: Re: Calculation of non-database columns
Date: 23:02 on 02 Jun 2005
On 6/2/05, Uwe Voelker <uwe.voelker@xxx.xx> wrote:
> Hello,
>=20
> I have a table with two dates ('from' and 'to'). I inflate them (with
> has_a) to a DateTime object.
>=20
> Now I want to calculate the timespan between these two DateTime objects
> everytime the record is read from the database. Can I use TEMP columns
> for this? How? (The problem is not the calculation itself, it's the
> Class-DBI context.)
>=20
> Or should I use trigger? But which one? The two DateTime objects need
> already to be inflated.

how about something simple like this:

sub duration {
  my $self =3D shift;
  return $self->to - $self->from;
}

Put that into your table class, and call it like any other column.=20
The only drawback is that it is calculated evertime it is called, but
it is not an expensive operation so it shouldn't be a problem.

Cheers,

Cees

Calculation of non-database columns
Uwe Voelker 21:21 on 02 Jun 2005

Re: Calculation of non-database columns
Cees Hek 23:02 on 02 Jun 2005

Re: Calculation of non-database columns
Uwe Voelker 09:57 on 03 Jun 2005

Re: Calculation of non-database columns
Cees Hek 15:46 on 03 Jun 2005

Re: Calculation of non-database columns
Uwe Voelker 11:56 on 04 Jun 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52