[Phpwm] MySQL triggers, creating hashed id

Elliot Smith elliot at townx.org
Fri Aug 17 16:30:25 BST 2007


pete graham wrote:
> Regarding my last problem I have decided to store items in my database
> with a hash of each items id. Ideally I'd like to do this using
> triggers to keep everything nice and clean. However I'm feeling quite
> dumb today and can't work out how to do it. Here's my attempt:
>
> CREATE TRIGGER clips_create_hash BEFORE INSERT ON `clips` FOR EACH ROW SET
> NEW.id_hash = sha1(NEW.id);
>   
Just a thought, does LAST_INSERT_ID() work in the trigger context? Could 
you use that in an AFTER trigger?

Elliot
> This ends up setting all the hashes the same, I believe that it's
> getting 0 for the value of NEW.id. This makes sense since id is a
> auto-incrementing primary key so wouldn't exist before the insert. But
> if I try to change the trigger to make it 'AFTER' I get this:
>
> "Updating of NEW row is not allowed in after trigger"
>
> Any help greatly appreciated.
>
> Thanks, Pete
>
> _______________________________________________
> Phpwm mailing list
> Phpwm at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/phpwm
>   




More information about the Phpwm mailing list