MySQL Forums
Forum List  »  Triggers

Re: Dynamically Referencing OLD/NEW values?
Posted by: Jens Kabella
Date: January 30, 2013 02:40AM

I have the same Problem, but i am a little bit further...

I´ve read the fields dynamically from the infomation_schema.columns Table into an cursor.
Then I will get the field names. Now the last Problem is. To get the valus from the NEW/OLD Table.

for example NEW.my_dynamic_col_name.

Is there anyone with an idea?

There is an error if i want to get the Values with NEW.col_name...

here is my code

CREATE TRIGGER insert_energy_values
AFTER INSERT ON energy_values FOR EACH ROW BEGIN
DECLARE record_not_found INTEGER DEFAULT 0;
DECLARE col_name Text;
DECLARE cur1 CURSOR FOR SELECT column_name FROM information_schema.COLUMNS
WHERE table_name = 'mytable';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET record_not_found = 1;
OPEN cur1;
my_loop: loop

fetch cur1 into col_name;

if record_not_found then
leave my_loop;
end if;


CALL insert_LogEntry ('i','mytable',colname,NEW.col_name,Current_Timestamp,1,USER());

end loop my_loop;
close cur1;
END;

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Dynamically Referencing OLD/NEW values?
2377
January 30, 2013 02:40AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.