MySQL Forums
Forum List  »  Triggers

Re: problemas concatenando en trigger
Posted by: Peter Brawley
Date: September 15, 2011 02:23PM

drop table if exists cv,traza_auditoria;
create table cv(a varchar(255));
create table traza_auditoria(operacion varchar(255),datos varchar(255));

drop trigger if exists lpa_cv;
delimiter go
CREATE TRIGGER `prueba` AFTER UPDATE ON `cv` FOR EACH ROW
begin
  declare n_traza int;
  declare viejo varchar(255);
  declare nuevo varchar(255);
  declare viejos varchar(255);
  declare nuevos varchar(255);
  DECLARE i int;
  DECLARE done INT DEFAULT 0;
  DECLARE a VARCHAR(255);
  DECLARE b,c INT;

  DECLARE cur1 CURSOR FOR 
    SELECT column_name from INFORMATION_SCHEMA.COLUMNS where table_name='cv';
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

  OPEN cur1;
  read_loop: LOOP
    FETCH cur1 INTO a;
    IF done THEN
      LEAVE read_loop;
    END IF;
    set @p = concat('old.', a );
    select @p into viejos;
    set @p1 = concat('new.',a);
    select @p1 into nuevos;
    INSERT INTO traza_auditoria (operacion,datos) VALUES (viejos,nuevos);
  END LOOP;
  CLOSE cur1;
end; 
go
delimiter ;

insert into cv values('1');
update cv set a='2';
select * from cv;
+------+
| a    |
+------+
| 2    |
+------+
select * from traza_auditoria;
+-----------+-------+
| operacion | datos |
+-----------+-------+
| old.a     | new.a |
+-----------+-------+

PB

Options: ReplyQuote


Subject
Views
Written By
Posted
2738
September 15, 2011 01:44PM
Re: problemas concatenando en trigger
1312
September 15, 2011 02:23PM


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.