[Dbix-class] Optimistic locking

Dan Horne dan.horne at redbone.co.nz
Fri Aug 4 19:56:00 CEST 2006


On Behalf Of David Wheeler
> Sent: Saturday, 5 August 2006 5:32 a.m.
> 
> > So, my question is: Is there any way to create such a pseudocolumn
> > that can
> > be populated as a result of the values of the other columns?
> 
> If you want to use a real column, you can add it to your table and
> then add a trigger to the table to compute the hash. Something like
> this (in PostgreSQL):
> 
> CREATE OR REPLACE FUNCTION hash_row() RETURNS trigger AS $$
>    NEW.hash = md5(NEW.foo || NEW.bar || NEW.baz);
>    RETURN NEW;
> $$ LANGUAGE sql;
> 
> CREATE TRIGGER hash_row BEFORE UPDATE OR INSERT ON mytable
> FOR EACH ROW EXECUTE PROCEDURE hash_row();
> 

Thanks, David

Alas, I'm using a version of MySQL that doesn't support triggers!

Dan




More information about the Dbix-class mailing list