I have an event that puts NULL instead of the proper value in a field while the requests, ran by hand 1 after the other, work just fine.
The event is ran via MySQL's scheduler every 10 seconds.
Here is my event's code:
BEGIN
DECLARE id INT;
DECLARE reqtype varchar(15);
SELECT t1.id into @id from ticket as t1, ticket_request as t2 , ticket_request as t3 WHERE t2.parent_request_id = t1.id and t3.id=t1.id and t2.request_type<>t3.request_type order by t1.id desc LIMIT 1;
IF @id > 0
THEN
select request_type into @reqtype from ticket_request where id=@id;
update ticket_request as t set t.request_type=@reqtype where t.parent_request_id=@id;
END IF;
END
Now, individually, these requests give:
SELECT t1.id from ticket as t1, ticket_request as t2 , ticket_request as t3 WHERE t2.parent_request_id = t1.id and t3.id=t1.id and t2.request_type<>t3.request_type order by t1.id desc LIMIT 1;
Outputs 3118
select request_type from ticket_request where id=3118;
Outputs service_request. And...
update ticket_request as t set t.request_type='service_request' where t.parent_request_id=3318;
Gives the desired result. The child's request type is updated with the parent.
When ran into an event, everything is working fine but the update puts a NULL in my t.request_type. The correct child is updated, and only that one... So I know the update is working, at least partially.
Here is the data before
id request_type parent_request_id
3118 service_request null
4556 incident 3118
And the one I'd like to see after
id request_type parent_request_id
3118 service_request null
4556 service_request 3118
Anyone has an idea of what is going wrong?