I've got a MySql function called Base52Encode, which takes in a bigint and returns a varchar(12).
I've got a table called Things that has a bigint auto_increment for the primary key, called ThingId, and a second column of type varchar(12), called ShortCode.
I want to set the value of ShortCode to the base-52 encoded value of the ThingId primary key, which gets created via the auto_increment.
DELIMITER $$
CREATE TRIGGER BeforeInsertThings
BEFORE INSERT ON Things
FOR EACH ROW
BEGIN
set new.ShortCode = Base52Encode(new.ThingId);
END $$
But whenever I insert a row, the ShortCode value always gets set to 0 (zero), which means the value being passed into Base52Encode is also a zero.
I'm assuming the issue is that the auto_increment value hasn't kicked in yet when this trigger runs.
So how exactly can I solve this issue?