Gleb Paharenko wrote:
Hello.
It seems that you forgot to OPEN the cursor. The trigger should be
similar to this one:
CREATE TRIGGER trigger_registration_and_attendance_before_insert
BEFORE INSERT
ON registration_and_attendance
FOR EACH ROW
BEGIN
DECLARE schedule_class_id INT;
DECLARE schedule_class_id_cursor CURSOR FOR
SELECT class_id
FROM schedules
WHERE schedules.id = new.schedule_id;
OPEN schedule_class_id_cursor;
FETCH schedule_class_id_cursor INTO schedule_class_id;
SET new.class_id = schedule_class_id;
CLOSE schedule_class_id_cursor ;
END;
Ferindo Middleton Jr wrote:
Is it possible to SET values on fields that involve the TABLE that
invoked the TRIGGER with SET actions.
I have the following lines in my trigger:
delimiter //
CREATE TRIGGER trigger_registration_and_attendance_before_insert
BEFORE INSERT
ON registration_and_attendance
FOR EACH ROW
BEGIN
DECLARE schedule_class_id INT;
DECLARE schedule_class_id_cursor CURSOR FOR SELECT class_id FROM
schedules WHERE schedules.id =
new.schedule_id;
FETCH schedule_class_id_cursor INTO schedule_class_id;
SET new.class_id = schedule_class_id;
END;
The server accepts this but "new.class_id" doesn't get a value when I do
an INSERT. Why won't this work?
Ferindo
Hi,
I tried the code above, opening and the cursor before assigning the
value called from the declaration into new.class_id but it still doesn't
work. The class_id field isn't picking up the value it should from my
schedules table. I can't figure out why - frustrating this. Thanks.
Ferindo
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]